What is the output of the following program?ct = ['CT', 'for', 'CodeTantra']ct2 = [i[0].upper() for i in ct]print(ct2)Options['C', 'F', 'C']['CT', 'FOR', 'CODETANTRA']Compilation error['CT']
Question
What is the output of the following program?ct = ['CT', 'for', 'CodeTantra']ct2 = [i[0].upper() for i in ct]print(ct2)Options['C', 'F', 'C']['CT', 'FOR', 'CODETANTRA']Compilation error['CT']
Solution
The output of the given Python program will be ['C', 'F', 'C'].
Here's the step by step explanation:
-
We have a list
ctwith the elements 'CT', 'for', 'CodeTantra'. -
We then create a new list
ct2using a list comprehension.
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? ct = [x for x in (x for x in 'CT 22966 for CodeTantra' if x.isdigit()) if(x in ([x for x in range(20)]))]print(ct)Options[2, 2, 9, 6, 6]Compilation errorRuntime error[ ]
What is the output of the following?ct = ['code', 'tantra']for x in ct: ct.append(x.upper())print(ct)OptionsNone of these[‘code’, ‘tantra’].[‘CODE’, ‘TANTRA’].[None, None].
What will be the output of the following Python code snippet?ct = [0, 1, 2, 3]for ct[0] in ct: print(ct[0])Options01233333error0122
What will be the output of the following Python code?ct = [[[4, 5], [6, 7]], [[9, 18], [1, 2]]] print(ct[1][0][1])Options16184
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.