Robotics & Artificial Intelligence
What will be the output of the following Python code?
s = "Great Day"
print(s.count('a'))
print(s.startswith('g'))
Answer
2
False
Working
In the string "Great Day":
The statement
s.count('a')counts the number of occurrences of lowercase'a'in the string. It appears 2 times, hence the output is 2.The statement
s.startswith('g')checks whether the string starts with lowercase'g'. Since the string starts with uppercase'G', it returns False as Python is case-sensitive.
Hence, the output is:
2
False
Related Questions
What will be the output of the following Python code?
a = 5 b = 3 print(a > b and b < 3)What will be the output of the following Python code?
str1 = 'PYTHON' print(str1[1:4])What are Assistant Robots?
Give any two differences between deterministic computing and probabilistic computing with an example.