Font size
WorksheetsPython test-XIII
Total questions: 54
Worksheet time: 28mins
What is the output of the following piece of code when executed in Python shell?
a=('Check')*3
('Check','Check','Check')
* Operator not valid for tuples
('CheckCheckCheck')
What is the output of the following
aTuple = (10, 20, 30, 40, 50, 60, 70, 80)
print(aTuple[:4:-1])
(30,40,50)
(20,30,40,50)
(80,70,60)
(80,60,40,30)
Choose the correct way to access value 20 from the following tuple
aTuple = ("abc","Apple",[1,0,3,20])
aTuple[1:2][1]
aTuple[1:2](1)
aTuple[2][3]
aTuple[1][3]
What is the output of the following
aTuple = ("Yellow", 20.4, "Red")
a, b, c = aTuple
len(b)
4
Error
3
predict the output:
t=(20,30,10,23,45,87,11)
sorted(T,reverse=False)
print(t)
Error
(10,11,20,23,30,45,87)
(87,45,30,23,20,11,10)
(20,30,10,23,45,87,11)
Select most suitable code to create a tuple with a single element:
t=('a',)
t=['a']
t=('a')
What will be the output of the following Python code?
t=(1,2,4,3)
t.sorted()
print(t)
(1,2,3,4)
(2,4,3,1)
(4,3,2,1)
(1,2,3,4)
What will be the output of the following Python code?
t1 = (1, 2, 4, 3)
t2 = (1, 2, 3, 4)
t1 ==t2
Error
True
None
False
What will be the output of the following Python code?
my_tuple = (1, 2, 3, 4)
my_tuple+=((5, 6, 7) ,)
print len(my_tuple)
7
5
Error
1
Suppose t = (1, 2, 4, 3), which of the following is incorrect?
print(t.sort())
print(t[3])
print(max(t))
print(len(t))
What will be the output of the following Python code?
tp1=(2,4,3)
tp3=tp1*2
print(tp3)
(4,8,6)
(2,4,3,2,4,3)
(2,2,4,4,3,3)
Error
What will be the output of the following Python code?
tp=()
tp1=tp*2
print(len(tp1)
0
2
1
Error
Which of the following will create a single element tuple?
(1,)
(1)
([1])
None of these
What will be the output of the following Python code?
tp=(5)
tp1=tp*2
print(len(tp1))
0
2
1
Error
What will be the output of the following Python code?
tp=(5,)
tp1=tp*2
print(len(tp1))
0
1
2
Error
Which of the following is a Python tuple?
[1, 2, 3]
(1, 2, 3)
1, 2, 3}
{}
Suppose t = (1, 2, 4, 3), which of the following is incorrect?
print(t[3])
t[3] = 45
print(max(t))
print(len(t))
What will be the output of the following Python code?
>>>t=(1,2,4,3)
>>>t[1:3]
(1, 2)
(1, 2, 4)
(2, 4)
(2, 4, 3)
What will be the output of the following Python code?
>>>t = (1, 2)
>>>2 * t
(1, 2, 1, 2)
[1, 2, 1, 2]
(1, 1, 2, 2)
[1, 1, 2, 2]
What will be the output of the following Python code?
>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
1
2
5
Error
What is the data type of (1)?
Tuple
Integer
List
Both tuple and integer
If a=(1,2,3,4), a[1:-1] is _________
Error, tuple slicing doesn’t exist
[2,3]
(2,3,4)
(2,3)
What will be the output of the following Python code?
>>> a=(1,2,3,4)
>>> del(a[2])
Now, a=(1,2,4)
Now, a=(1,3,4)
Now a=(3,4)
Error as tuple is immutable
Is the following Python code valid?
>>> a=(1,2,3,4)
>>> del a
No because tuple is immutable
Yes, first element in the tuple is deleted
Yes, the entire tuple is deleted
No, invalid syntax for del method
What type of data is: a=[(1,1),(2,4),(3,9)]?
Array of tuples
List of tuples
Tuples of lists
Invalid type
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
Tuples in Python are mutable
False
True
How to create a single element tuple
(1,)
(1)
{1}
[1]
tuple([1])
Result of the program above is
('1', '2', '3', '4', '5')
(1, 2, 3, 4, 5)
12345
"12345"
What is the output of the program above
<class 'tuple'>
<class 'None'>
<class 'list'>
<class 'int'>
What is the output of the code above
(1, '2', 3, 4, 5)
syntax error
(1, 2, 3, 4, 5)
('1', '2', '3', '4', '5')
Which of the following is true
a is assigned a value of 1
b is assigned a value of [2,3]
b is assigned a value of (2,3)
b is assigned a value of 2
What is the output of the program above ?
b is bigger
a is bigger
Syntax error : tuples can't be compared
What is the output of the code above ?
1 4
1
1 None
1 [2,3,4]
1 (2,3,4)
What is the output of the program above ?
True
False
