CBSE Class 11 Computer Science Question 62 of 91

String Manipulation — Question 7

Back to all questions
7
Question

Question 2b

What will be the output produced by following code fragments?

x = "hello" + \
"to Python" + \
"world"
for char in x :
    y = char
    print (y, ' : ', end = ' ')

Answer

Output
h  :  e  :  l  :  l  :  o  :  t  :  o  :     :  P  :  y  :  t  :  h  :  o  :  n  :  w  :  o  :  r  :  l  :  d  : 
Explanation

Inside the for loop, we are traversing the string "helloto Pythonworld" character by character and printing each character followed by a colon (:).

Answer