What is the output of the following program?line = "What will have so will" L = line.split('a') for i in L: print(i, end=' ')
Question
What is the output of the following program?line = "What will have so will" L = line.split('a') for i in L: print(i, end=' ')
Solution
The output of the program will be:
Wh t will h ve so will
Here's the step-by-step explanation:
-
The
split()function in Python separates a string into a list where each word is a list item. In this case, the stringlineis split at every occurrence of the letter 'a'. -
The resulting list
Lis: ['Wh', 't will h', 've so will'] -
The
forloop then iterates over each item in the listLand prints it. Theend=' 'argument in theprint()function specifies that a space should be used at the end of each printed item instead of a newline (which is the default behavior ofprint()). -
Therefore, the items in the list are printed on one line with a space between each item.
Similar Questions
What is the output of the following program?ct = "I will learn coding"P = ct.split('i')for i in P: print(i, end=' ')Options[‘I w’, ‘ll learn cod’, ‘ng’][‘I’, ‘will’, ‘learn’, ‘coding’]I w ll learn cod ngI will learn coding
10.What will be the output of the following Python code?string = "my name is x"for i in string.split(): print (i, end=", ")
What will be the output of the following Python code snippet?xyz = "How are you?"for k in ' '.join(xyz.split()): print (k, end=", ")OptionsH, o, w, , a, r, e, , y, o, u, ?,How, are, you?,errorH, o, w, , a, r, e, , y, o, u, ?
What is the output of the following code in Python?
What is the output of following?print(“abcabcab”.split(‘c’))
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.