WorksheetsPython - List and Tuples
Total questions: 20
Worksheet time: 10mins
What is the output of the following piece of code when executed in Python shell?
>>> a=("Check")*3
>>> a
(‘Check’,’Check’,’Check’)
* Operator not valid for tuples
(‘CheckCheckCheck’)
Syntax error
Is the following piece of code valid?
>>> a=(1,2,3,4)
>>> del a
No because tuple is immutable
Yes, the entire tuple is deleted
No, invalid syntax for del method
Yes, first element in the tuple is deleted
What type of data is: a=[(1,1),(2,4),(3,9)]?
Array of tuples
List of tuples
Tuples of lists
Invalid type
Which of the following is true for a tuple?
Tup = 1,2,3
Tup = (""1,"2)
Tup = (1,2,3,4)
None of the above
Result of the program above is
('1', '2', '3', '4', '5')
(1, 2, 3, 4, 5)
12345
"12345"
Suppose you have the following tuple definition:
t = ('foo', 'bar', 'baz')
Which of the following statements replaces the second element ('bar') with the string 'qux':
t[1] = 'qux'
t(1) = 'qux'
t[1:1] = 'qux'
error
If list=[17,23,41,10] then list.append(32) will result
[32,17,23,41,10]
[17,23,41,10,32]
[10,17,23,32,41]
[41,32,23,17,10]
Suppose list=[12,3,22,"mago","hello"], what is list[-6]
Error
None
mango
12
L_names=['Harsh','Amit','Sahil','Viresh']
min(L_names)
'Harsh'
'Amit'
'Viresh'
None of the above
L_names=['Harsh','Amit','Sahil','Viresh']
L_names.pop()
'Harsh'
'Amit'
'Viresh'
None of the above
If L1=[2,4,8,16], L2=[32,64] what is L1+L2
[2,4,8,16,32,64]
[2,4,8,16][32,64]
[2,4,8,16],[32,64]
None of the above
If L1=[2,4,8,16] What is the result of the following statement
16 in L1
True
False
L=[2,4,8,16,32,64] what is L[:2]
[2,4]
[2,4,8]
2,4
None of the above
T=((1,2,3),(3,4))
what is T[1][1]
4
3
2
1
Which function can be used to convert list to a tuple
tuple
list
to_list
to_tuple
Suppose list1 is [1, 3, 2], What is list1 * 2 ?
[2, 6, 4].
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
To remove string “hello” from list1, we use which command?
list1.remove(“hello”)
list1.remove(hello)
list.remove(“hello”)
list.remove(hello)
Suppose a tuple T is declared as T=(20,36,34,49), which of the following is incorrect?
print(T[3])
T[3] = 49
print(min(T))
print(T.count(20))
Identify the data type of T:
T = [‘A’, ‘23’, ‘92’, ‘(10,20)’]
List
Dictionary
String
Tuple
What is the output of the code?
a = (33, 55)
a.append(22)
print(a)
33 55 22
33
55
22
33, 55, 22
Error
