Robotics & Artificial Intelligence
What would be the output of following code?
Q1 = "Hello How are you"
val = Q1.count("H")
print(val)
- 1
- 3
- 2
- Error
Python String Manipulation
1 Like
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
The method used to check that string contains all lower case letter is …………… .
- lower()
- small()
- issmall()
- islower()
What would be the output of following code …………… .
str1 = "Hello India" s1 = str1[1:3] print(s1)- He
- el
- Hlo
- None of these
The method used to check that all characters in a string are alpha numeric is …………… .
- isal()
- isalnum()
- isnum()
- isalphanum()
What would be the output of following code?
information = "I am studying in class X !" val = information.find("studying") print("The index is: ", val)- 5
- 6
- 7
- Error