Computer Science
Consider the following code and find out the error:
T1 = ('A')
T2 = ('B', 'C', 3)
T3 = T1 + T2
Python Tuples
3 Likes
Answer
The code raises an error because T1 is not recognized as a tuple but as a string due to the missing comma. A single-element tuple needs a trailing comma, like T1 = ('A',). Therefore, T1 is a string, and concatenating a string with a tuple using T1 + T2 is not allowed, causing the error.
Answered By
1 Like
Related Questions
Consider the following code and find out the error:
tup1=('A', 'school', 10.5, 70) print max(tup1)Consider the following code and find out the error:
t = (10, 20, 30, 40) t[1] = 'o'Consider the following code and find out the error:
T1 = (10, 20, 30, 40) T2 = (40, 50, 60) T1, T2, T3 = T1, T2t1 = (100, 200, "Global", 3, 3.5, "Exam", [1, 2], (30, 40), (3, 5, 3)) :
Consider the above tuple 't1' and answer the following questions:
(a) len(t1)
(b) 20 not in t1
(c) t1[-8:-4]
(d) t1[5:]
(e) t1.index(5)
(f) t1.index(3, 6)
(g) 10 in t1
(h) t1.count(3)
(i) any(t1)
(j) t1[2]*2