CBSE Class 12 Computer Science Question 88 of 105

Python Revision Tour — Question 14

Back to all questions
14
Question

Question 2m

Predict the output of the following code fragments:

x = "apple, pear, peach"
y = x.split(", ")
for z in y :
   print(z)
Answer
Output
apple
pear
peach
Explanation

x.split(", ") breaks up string x into a list of strings so y becomes ['apple', 'pear', 'peach']. The for loop iterates over this list and prints each string one by one.