Test Index

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

© examsnet.com
Question : 1 of 37
Marks: +1, -0
State if following statement is True or False :
If T is a tuple and L is a list, then T+L is a valid statement in Python.
Solution:  
Concept:
The + operator joins (concatenates) two sequences only when both are of the same type: tuple + tuple, list + list or string + string.
Explanation:
>>> T = (1, 2)
>>> L = [3]
>>> T + L
TypeError: can only concatenate tuple (not "list") to tuple
A tuple cannot be added to a list, so T+L raises a TypeError. The statement is false.
Key point: Convert first if you need to join them: T + tuple(L) gives a tuple and list(T) + L gives a list.
Answer:
Option B (False)
© examsnet.com
Advertisements
Go to Question: