Robotics & Artificial Intelligence

What will be the output of the following Python code?

s = "Great Day"
print(s.count('a'))
print(s.startswith('g'))

Python String Manipulation

3 Likes

Answer

2
False

Working

In the string "Great Day":

  1. 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.

  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

Answered By

2 Likes


Related Questions