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
Question
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
Solution
The output of the program will be ['code', 'tantra'].
Here's the step by step explanation:
-
The list 'c' is defined with two string elements: 'code' and 'tantra'.
-
The 'for' loop goes through each element 't' in the list 'c'.
-
The 'upper()' function is called on 't', which converts the string to uppercase. However, this doesn't change the original list because strings in Python are immutable and the 'upper()' function returns a new string.
-
The 'print(c)' statement prints the original list 'c', which hasn't been changed by the 'upper()' function.
So, the correct option is ['code', 'tantra'].
Similar Questions
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 is the output of the following program?c = 4231for t in c: print(t)Options42314 3 2Error4231
What is the output of the following program?for t in [4, 2, 3, 1][::-1]: print (t)Options1 3 2 41 3 2 43 2 41324
What will be the output of the following Python code?>>>pythonclass = "code tantra">>>print("%s" % pythonclass[4:7])Optionstantratacont
What will be the output of the following Python code?print("code. TANTRA".capitalize())OptionsCODE. TANTRAcode. tantraCode. tantraAbc. Def
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.