Computer Science
How many times is the word 'HELLO' printed in the following statement?
s = "python rocks"
for ch in s:
print ("Hello")
Python String Manipulation
2 Likes
Answer
The word 'Hello' is printed 12 times in the given Python code because the string s = "python rocks" contains 12 characters. The for loop iterates through each character in the string, printing 'Hello' once for each character, resulting in a total of 12 prints.
Answered By
2 Likes
Related Questions
How does '*' operator behave on strings?
Explain function split() with an example.
Write the output of the following:
>>> x = "hello" >>> print(x[1:-2])Write the output of the following:
string = "Hello Madam, I love Tutorials" substring = "Madam" if string.find(substring) != -1: print("Python found the substring!") else: print("Python did NOT find the substring!")