NEW
Font size
WorksheetsLIST-TUPLES-SET-DICTIONARY
Total questions: 25
Worksheet time: 13mins
Which of the following commands will create a list?
list1 = list()
list1 = list()
list1 = list([1, 2, 3])
all of the mentioned
What is the output when we execute list(“hello”)?
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
[‘hello’]
[‘hello’]
None of the Above
To shuffle the list(say list1) what function do we use?
list1.shuffle()
shuffle(list1)
random.shuffle(list1)
random.shuffleList(list1)
Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
[2, 33, 222, 14]
Error
25
[25, 14, 222, 33, 2]
>>>names = ['Amir', 'Bear', 'Charlton', 'Daman'] >>>print(names[-1][-1])
A
Daman
Error
n
Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?
0
1
4
2
To insert 5 to the third position in list1, we use which command?
list1.insert(3, 5)
list1.insert(2, 5)
list1.add(3, 5)
list1.append(3, 5)
Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3]
what is list1 after listExample.pop()?
[3, 4, 5, 20, 5, 25, 1]
[1, 3, 3, 4, 5, 5, 20, 25]
[3, 5, 20, 5, 25, 1, 3]
[1, 3, 4, 5, 20, 5, 25]
numbers = [1, 2, 3, 4]
numbers.append([5,6,7,8])
print(len(numbers))
4
5
8
12
veggies = ['carrot', 'broccoli', 'potato', 'asparagus'] veggies.insert(veggies.index('broccoli'), 'celery') print(veggies)
[‘carrot’, ‘celery’, ‘broccoli’, ‘potato’, ‘asparagus’]
[‘carrot’, ‘celery’, ‘potato’, ‘asparagus’]
[‘carrot’, ‘broccoli’, ‘celery’, ‘potato’, ‘asparagus’]
[‘carrot’, ‘broccoli’, ‘celery’, ‘potato’, ‘asparagus’]
What will be the output of the following Python code?
>>>my_tuple = (1, 2, 3, 4)
>>>my_tuple.append( (5, 6, 7) )
>>>print len(my_tuple)
1
2
5
Error
If a=(1,2,3,4), a[1:-1] is _________
Error, tuple slicing doesn’t exist
[2,3]
(2,3,4)
(2,3)
Is the following Python code valid?
>>> a=(1,2,3)
>>> b=('A','B','C')
>>> c=tuple(zip(a,b))
Yes, c will be ((1, ‘A’), (2, ‘B’), (3, ‘C’))
Yes, c will be ((1,2,3),(‘A’,’B’,’C’))
No because tuples are immutable
No because the syntax for zip function isn’t valid
Is the following Python code valid?
>>> a,b,c=1,2,3
>>> a,b,c
Yes, [1,2,3] is printed
No, invalid syntax
Yes, (1,2,3) is printed
1 is printed
What will be the output of the following Python code?
>>> a=(1,2)
>>> b=(3,4)
>>> c=a+b
>>> c
(4,6)
(1,2,3,4)
Error as tuples are immutable
None
Which of these about a set is not true?
Mutable data type
Allows duplicate values
Data type with unordered values
Immutable data type
What will be the output of the following Python code?
nums = set([1,1,2,3,3,3,4,4])
print(len(nums))
7
Error
4
8
Which of the following statements is used to create an empty set?
{ }
set( )
[ ]
( )
If a={5,6,7,8}, which of the following statements is false?
print(len(a))
print(min(a))
a.remove(5)
a[2]=45
What will be the output of the following Python code?
>>> a={4,5,6}
>>> b={2,8,6}
>>> a+b
{4,5,6,2,8}
{4,5,6,2,8,6}
Error as unsupported operand type for sets
Error as the duplicate item 6 is present in both sets
What will be the output of the following Python code?
>>> a={4,5,6}
>>> b={2,8,6}
>>> a-b
{4,5}
{6}
Error as unsupported operand type for set data type
Error as the duplicate item 6 is present in both sets
What will be the output of the following Python code?
>>> a={3,4,5}
>>> a.update([1,2,3])
>>> a
Error, no method called update for set data type
{1, 2, 3, 4, 5}
Error, list can’t be added to set
Error, duplicate item present in list
Which of the following statements create a dictionary?
d = {}
d = {“john”:40, “peter”:45}
d = {40:”john”, 45:”peter”}
All of the mentioned
What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
print(list(d.keys()))
[“john”, “peter”]
[“john”:40, “peter”:45]
(“john”, “peter”)
(“john”:40, “peter”:45)
What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
for i,j in a.items():
print(i,j,end=" ")
1 A 2 B 3 C
1 2 3
A B C
1:”A” 2:”B” 3:”C”
