Robotics & Artificial Intelligence

What would be the output of following code?

Q1 = "Hello How are you"
val = Q1.count("H")
print(val)
  1. 1
  2. 3
  3. 2
  4. Error

Python String Manipulation

3 Likes

Answer

2

Reason — The count() function returns the number of occurrences of a character in a string. In the string "Hello How are you", the character "H" appears two times, therefore the output is 2.

Answered By

2 Likes


Related Questions