x = 'Python Pi Py Pip'
print(x.count('p'))
The code defines a string variable named x and assigns the value 'Python Pi Py Pip' to it. Then, it uses the count() method to count the number of occurrences of the letter 'p' in the string. The count() method returns an integer value, which is the number of times the specified substring is found within the string.
In this case, the string 'Python Pi Py Pip' contains one lowercase letter 'p'. Therefore, the output of the code is:
1
0 Comments:
Post a Comment