Test Index
Python Revision Tour
© examsnet.com
Question : 74 of 102
Marks:
+1,
-0
Predict the output of the following code :
d={"IND":"DEL","SRI":"COL","CHI":"BEI"}str1=""for i in d: str1=str1+str(d[i])+"@" str2=str1[:-1]print (str2)[CBSE 2024 Compartment]
Solution:
Explanation:A
for loop over a dictionary gives its keys in insertion order: "IND", "SRI", "CHI". d[i] is the value.| i | d[i] | str1 | str2 = str1[:-1] |
| IND | DEL | DEL@ | DEL |
| SRI | COL | DEL@COL@ | DEL@COL |
| CHI | BEI | DEL@COL@BEI@ | DEL@COL@BEI |
str1[:-1] drops the last character (the final @).Output:DEL@COL@BEI
© examsnet.com
Go to Question: