Test Index

CBSE Class 12 Computer Science 2026 Paper Compartment Get it on Google PlayDownload on the App Store

© examsnet.com
Question : 4 of 37
Marks: +1, -0
What will be the output of the following Python code ?
try:
num = 5
text = "15"
result = str(num) + text
print(result)
except:
print("Error")
Solution:  
Concept:
+ between two strings joins (concatenates) them. The except block runs only if an error occurs in the try block.
Explanation:
str(num) = "5"
"5" + "15" = "515"
No error occurs, so print(result) prints 515 and the except block is skipped.
Output:
515
Key point: 20 would need num + int(text); Error would appear only for num + text (int + str).
Answer:
Option B (515)
© examsnet.com
Advertisements
Go to Question: