What will be the output of A + B, if A is a tuple and B = 5? (python)
Answers
Answer:
Explanation:
This section focuses on the "Tuple" in Python. These Multiple Choice Questions (mcq) should be practiced to improve the Python skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Which of the following creates a tuple?
A. tuple1=("a","b")
B. tuple1[2]=("a","b")
C. tuple1=(5)*2
D. None of the above
View Answer
Answer:
TypeError: can only concatenate tuple (not "int") to tuple
Explanation:
The reason for the error is that tuples (it also applies to string and lists) can only concatenate tuples (not any other data type)
You can look at the attachments for the justification.
Remedial Steps:
If you really want to add 5, then you need to convert into tuple by putting b=(5,) in order to concatenate.