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
Question
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
Solution
The output of the program will be: 'I w ll learn cod ng'.
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 stringctis split at each 'i'. -
The string
ctis "I will learn coding". When this is split at each 'i', it becomes ['I w', 'll learn cod', 'ng']. -
The
forloop then iterates over each item in the list and prints it. Theend=' 'in theprint()function puts a space after each printed item instead of a newline, so all the items are printed on the same line with a space between each one. -
Therefore, the output is 'I w ll learn cod ng'.
Similar Questions
What is the output of the following program?c = ['code', 'tantra']for t in c: t.upper()print(c)Options['code', 'tantra']CODE['CODE' , 'TANTRA']TANTRA
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=' ')
What will be the output of the following Python code snippet?print('12abcdeabcopabc'.split('abc'))Options['12', 'de', 'op']('12', 'de', 'op')('12', 'de', 'op', '')['12', 'de', 'op', '']
What is the output of the following program?ct = ['CT', 'for', 'CodeTantra']ct2 = [i[0].upper() for i in ct]print(ct2)OptionsCompilation error['CT']['C', 'F', 'C']['CT', 'FOR', 'CODETANTRA']
What will be the output of the following Python code snippet?ct = [0, 1, 2, 3]for ct[-1] in ct: print(ct[-1], end = " ")Options0 1 2 33 3 3 3error0 1 2 2
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.