Indexing
Slicing
Concatenation
Element assignment
Output of the code:
t = (10, 20, 30)t += (40,)print(t)
(10, 20, 30)
(10, 20, 30, 40)
Error
(40,)
What will be the output?
t = (1, 2, 3)t[1] = 5print(t)
(1, 5, 3)
(1, 2, 3)
None
Dictionary
Tuple
Set
List
('abc’)
('a', 'b', 'c’)
['a', 'b', 'c’]
list
set
tuple
dictionary
In Python, a tuple can contain only integers as its elements.
In Python, a tuple can contain only strings as its elements.
In Python, a tuple can contain both integers and strings as its elements.
In Python, a tuple can contain either string or integer but not both at a time.
t = (5)print(type(t))
<class 'tuple'>
<class 'int'>
<class 'list'>
[1, 2, 3]
{1, 2, 3}
{}
Built in
Derived data
(1)
(1,)
[1]
{1}
What will be the output of the following Python code?
tuple1=(5,1,7,6,2)tuple1.pop(2)print(tuple1)
(5,1,6,2)
(5,1,7,6)
(5,1,7,6,2)
Deletion of elements
Iteration
Tuples have structure; lists have an order
Tuples are homogeneous, lists are heterogeneous.
Tuples are immutable, lists are mutable.
All of them
t1=1,2,4
t1=(1,)
t1=tuple(“123”)
All of these
A collection of ordered and mutable data
A collection of unordered and mutable data with key-value pairs
A collection of immutable key-value pairs
A collection of values only
(10)
[10]
(10,)
{10}
What is the output of the following code ?
ms = ('A','D', 'H','U','N','I','C')print(ms[1:4])
(‘D’, ‘H’, ‘U’)
(‘A’, ‘D’, ‘H’,’U’,’N’,’I’,’C’)
(‘D’,’H’,’U’,’N’,’I’,’C’)
count()
len()
index()
find()
a, b, c = (10, 20, 30)print(b)
10
20
30
What will be the output of the following code?
a=((0,2,3,4)[1:-2])print(a)
(3,)
(2, )
(0,)
Error, tuple slicing doesn’t exist
[2,3]
(2,3,4)
(2,3)
empty_tuple = ()
empty_tuple = tuple()
empty_tuple = []
Both A and B
What will be the output of the following?
print(sum(1,2,3))
error
6
1
3
List of tuple
Tuple of List
Array of Tuples
Invalid Type
Yes, list mutable and tuple immutable
No, list and tuple both are mutable
No, list and tuple both are in immutable
No, just opposite, list immutable and tuple mutable
Array of tuples
List of tuples
Tuples of lists
Invalid type
Integer
Both tuple and integer
What is the output of the following?
print(max([1, 2, 3, 4.] [4, 5, 6], [7]))
[4,5, 6
[7]
[1, 2,3, 4]
7
dict
What is the output of the following statement ?
print ((2, 4) + (1, 5))
(2 , 4), (4 , 5)
(3 , 9)
(2, 4, 1, 5)
Invalid Syntax
print(t[3])
t[3] = 45
print(max(t))
print(len(t))
a=[(2,4),(1,2),(3,9)]a.sort()print(a)
[(1, 2), (2, 4), (3, 9)]
[(2,4),(1,2),(3,9)]
Error because tuples are immutable
Error, tuple has no sort attribute
append()
insert()
remove()
capitalize()
startswith()
pop()