Test Index

Python Revision Tour Get it on Google PlayDownload on the App Store CBSE Board Videos

© 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.
id[i]str1str2 = str1[:-1]
INDDELDEL@DEL
SRICOLDEL@COL@DEL@COL
CHIBEIDEL@COL@BEI@DEL@COL@BEI
str1[:-1] drops the last character (the final @).
Output:
DEL@COL@BEI
© examsnet.com
Advertisements
Go to Question: