What will be the output of the following Python code?
d = {0: 'a', 1: 'b', 2: 'c'}for x in d.values(): print(x)
0 1 2
a b c
0 a 1 b 2 c
none 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)
a={1:"A",2:"B",3:"C"}b={4:"D",5:"E"}a.update(b) print(a)
{1: ‘A’, 2: ‘B’, 3: ‘C’}
Method update() doesn’t exist for dictionaries
{1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}
{4: ‘D’, 5: ‘E’}
{1: ‘A’, 2: ‘B’}
dict([[1,”A”],[2,”B”]])
{1,”A”,2”B”}
{ }
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
a={1:"A",2:"B",3:"C"}print(a.get(3))
Error, invalid syntax
A
5
C
anywhere in between the file
End
beginning
second line of the file
d = {"john":40, "peter":45}print(d["john"])
40
45
“john”
“peter”
print('abcdefcdghcd'.split('cd', 0))
[‘abcdefcdghcd’]
‘abcdefcdghcd’
error
[1, 2, 3]
(1, 2, 3)
{1, 2, 3}
{}
print('abcdefcdghcd'.split('cd', -1))
[‘ab’, ‘ef’, ‘gh’]
[‘ab’, ‘ef’, ‘gh’, ”]
(‘ab’, ‘ef’, ‘gh’)
(‘ab’, ‘ef’, ‘gh’, ”)
print("xyyzxyzxzxyy".count('xyy', -10, -1))
2
0
1
print('ab cd ef'.title())
Ab cd ef
Ab cd eF
Ab Cd Ef
None of the mentioned
x = 'abcd'for i in range(len(x)): x[i].upper()print (x)
abcd
ABCD
Since “susan” is not a value in the set, Python raises a KeyError exception
It is executed fine and no exception is raised, and it returns None
Since “susan” is not a key in the set, Python raises a KeyError exception
Since “susan” is not a key in the set, Python raises a syntax error
('abc’)
('a', 'b', 'c’)
['a', 'b', 'c’]
Error
points = [[1, 2], [3, 1.5], [0.5, 0.5]]points.sort()print(points)
[[1, 2], [3, 1.5], [0.5, 0.5]]
[[3, 1.5], [1, 2], [0.5, 0.5]]
[[0.5, 0.5], [1, 2], [3, 1.5]]
[[0.5, 0.5], [3, 1.5], [1, 2]]
What is the output of following code
a = [5,2,3]print(a[5:])
[ ]
None
what is the output of the following code?
M=['b' *x for x in range(4)] print(M)
['', 'b', 'bb', 'bbb']
['b,'bb', "bbb', "bbbb']
['b','bb', bbb']
none of these
print('abcdefcdghcd'.split('cd', 2))
[‘ab’, ‘ef’, ‘ghcd’]
[‘ab’, ‘efcdghcd’]
[‘abcdef’, ‘ghcd’]
test = {1:'A', 2:'B', 3:'C'}del test[1]test[1] = 'D'del test[2]print(len(test))
Error as the key-value pair of 1:’A’ is already deleted
keys()
getkeys()
allkeys()
keyvalues()
What will be the result?
a = [1, 2, 3]print(a[1:])
[1]
[2, 3]
[1, 2]
print('xyyzxxyxyy'.lstrip('xyy'))
zxxyxyy
z
zxxy
a={1:"A",2:"B",3:"C"}a.clear() print(a)
{ None:None, None:None, None:None}
{1:None, 2:None, 3:None}
list1.shuffle()
shuffle(list1)
random.shuffle(list1)
random.shuffleList(list1)
print('Hello!2@#World'.istitle())
True
False
[3, 4, 5, 20, 5, 25, 1, 3]
[1, 3, 3, 4, 5, 5, 20, 25]
[25, 20, 5, 5, 4, 3, 3, 1]
[3, 1, 25, 5, 20, 5, 4, 3]
What is the correct command to shuffle the following list?
fruit=['apple', 'banana', 'papaya', 'cherry']
fruit.shuffle()
shuffle(fruit)
random.shuffle(fruit)
random.shuffleList(fruit)
print("xyyzxyzxzxyy".endswith("xyy"))
3
list1.sum(5)
list1.add(5)
listl.append(5)
list1.addelement(5)
getkeys ()
key()
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
What will be the output of the following code?
list1=[2,33,222,14,25]print(list1[-1])
33
14
25
What is the output of the following program:
print ("Hello World"[::-1])
dlroW olleH
Hello Worl
D
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
list1 = [11, 2, 23]list2 = [11, 2, 2]print(list1 < list2)
Mutable data type
Allows duplicate values
Data type with unordered values
Immutable data type
indexing
Replication
concatenation
None of the Above
What data type is the object below ?
L=[1, 23, 'hello', 1]
List
Dictionary
Tuple
Array
list1=[1,3]list2=list1list1[0]=4print(list2)
[1, 4]
[1,3, 4]
[4,3]
[1,3]
d = {}
d = {“john”:40, “peter”:45}
d = {40:”john”, 45:”peter”}
All of the mentioned
What will be the output?
dict1={'a':[3,6,8]}print(len(dict1))
print("Welcome to Python".split())
[“Welcome”, “to”, “Python”]
(“Welcome”, “to”, “Python”)
{“Welcome”, “to”, “Python”}
“Welcome”, “to”, “Python”
a=[1,2,3] b=a.append(4) print(a) print(b)
[1,2,3,4] [1,2,3,4]
[1, 2, 3, 4] None
Syntax error
[1,2,3] [1,2,3,4]
keys, keys
key values, keys
keys, key values
key values, key values
total={}def insert(items): if items in total: total[items] += 1 else: total[items] = 1insert('Apple')insert('Ball')insert('Apple') print (len(total))
What will be the output of the following ?
print((range(4)))
0,1,2,3
[0,1,2,3]
range(0, 4)
(0,1,2,3)
print('a@ 1,'.islower())
(1)
(1,)
{1}