How do you join two tuples in Python?
A
Using the + operator B
Using append() C
Using extend() D
Using join()
Analysis & Theory
The `+` operator concatenates two tuples and returns a new one.
What will this code output?
t1 = (1, 2); t2 = (3, 4)
t3 = t1 + t2
print(t3)
A
(1, 2, 3, 4) B
[1, 2, 3, 4] C
(3, 4, 1, 2) D
Error
Analysis & Theory
The `+` operator combines the two tuples in order.
Which of the following is valid tuple joining syntax?
A
tuple1.join(tuple2) B
tuple1.append(tuple2) C
tuple1 + tuple2 D
tuple1.extend(tuple2)
Analysis & Theory
`tuple1 + tuple2` is the correct way to join two tuples.
Can you join a tuple and a list using +?
A
Yes B
No C
Only in Python 2 D
Only if both are empty
Analysis & Theory
You cannot use `+` to join a tuple and a list. They are different types.
What will be the output of:
t = (1, 2) + (3,)
print(t)
A
(1, 2, 3) B
(1, 2)(3) C
[1, 2, 3] D
Error
Analysis & Theory
This adds a single-element tuple using correct syntax `(3,)`.
Which of the following will result in a TypeError?
A
(1, 2) + (3, 4) B
(1, 2) + [3, 4] C
(1,) + (2, 3) D
() + (0,)
Analysis & Theory
Tuples and lists cannot be added directly — will raise TypeError.
What will this code output?
a = ('a',); b = ('b', 'c')
print(a + b)
A
('a', 'b', 'c') B
['a', 'b', 'c'] C
'abc' D
Error
Analysis & Theory
Both are tuples, so `+` joins them: ('a', 'b', 'c').
Which operator is overloaded to allow tuple joining?
A
__add__ B
__join__ C
__concat__ D
__append__
Analysis & Theory
The `__add__()` method is used internally for `+` operator on tuples.
What is required when joining a single-item tuple?
A
Nothing special B
Use list instead C
You must add a comma after the item D
Use join()
Analysis & Theory
Single-item tuples must have a trailing comma: `(item,)`.
Which of the following joins three tuples correctly?
A
a + b + c B
a.append(b).append(c) C
a.extend(b + c) D
join(a, b, c)
Analysis & Theory
The `+` operator can be used multiple times to join several tuples.