getkeys()
key()
keys()
none of the mentioned
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
What will be the output of the following Python code?
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
What will be the output of the following Python code snippet?
print('Ab!2'.swapcase())
AB!@
ab12
aB!2
aB1@
d = {"john":40, "peter":45}print(list(d.keys()))
[“john”, “peter”]
[“john”:40, “peter”:45]
(“john”, “peter”)
(“john”:40, “peter”:45)
remove
pop
discard
dispose
Concatenation
Membership
Slicing
All of the above
[2, 6, 4]
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
Sequence value pair
Key value pair
Tuple value pair
Record value pair
print(list1[0])
print(list1[:2])
print(list1[:-2])
all of the mentioned
islower()
isupper()
Islower()
None
a=["Apple","Ball","Cobra"]a.sort(key=len)print(a)
[‘Apple’, ‘Ball’, ‘Cobra’]
[‘Ball’, ‘Apple’, ‘Cobra’]
[‘Cobra’, ‘Apple’, ‘Ball’]
Invalid syntax for sort()
What will be the output?
t = (1, 2, 3)t[1] = 5print(t)
(1, 5, 3)
Error
(1, 2, 3)
length
length()
len()
d.size()
len(d)
size(d)
d.len ()
example = "helle"print(example.find("e"))
-1
1
0
['llo']
['hello']
['h', 'e', l', 'l', 'o']
None of the above
print("abcdef".find("cd") == "cd" in "abcdef")
True
False
None of the mentioned
list1.addEnd (5)
list1.addLast (5)
list1.append (5)
list1.add(5)
List
Dictionary
Set
None of the Above
White Space
,
e
S
a={1:"A",2:"B",3:"C"}print(a.get(1,4))
A
4
Invalid syntax for get method
print('11'.isnumeric())
print('Hello!2@#World'.istitle())
error
for i in [1, 2, 3, 4][::-1]: print (i)
1 2 3 4
4 3 2 1
a={1:"A",2:"B",3:"C"}for i in a: print(i,end=" ")
1 2 3
‘A’ ‘B’ ‘C’
1 ‘A’ 2 ‘B’ 3 ‘C’
Error, it should be: for i in a.items():
print("xyyzxyzxzxyy".count('yy', 1))
2
list
set
tuple
dictionary
[1, 2, 3]
{1, 2, 3}
{}
a = {} a[1] = 1 a['1'] = 2 a[1.0]=4 count = 0 for i in a: count += a[i] print(count) print(a)
An exception is thrown
3
6
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.
d = {0, 1, 2}for x in d: print(x)
0 1 2
{0, 1, 2} {0, 1, 2} {0, 1, 2}
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 is the output of following code
x = [10, 20, 30]print(x * 0)
[0, 0, 0]
[ ]
What is the output of the following program:
print ("Hello World"[::-1])
dlroW olleH
Hello Worl
D
s[]
s.getitem(3)
s.__getitem__(3)
s.getItem(3)
More than one key isn’t allowed
Keys must be immutable
Keys must be integers
When duplicate keys encountered, the last assignment wins
print('abcdef'.partition('cd'))
(‘ab’, ‘ef’)
(‘abef’)
(‘ab’, ‘cd’, ‘ef’)
values = [[3, 4, 5, 1 ], [33, 6, 1, 2]]for row in values: row.sort() for element in row: print(element, end = " ") print()
The program prints two rows 3 4 5 1 followed by 33 6 1 2
The program prints on row 3 4 5 1 33 6 1 2
The program prints two rows 1 3 4 5 followed by 1 2 6 33
[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]
d1 = {"john":40, "peter":45}d2 = {"john":466, "peter":45}print(d1 == d2)
Mutable data type
Allows duplicate values
Data type with unordered values
Immutable data type
What will be printed?
a = [[1, 2], [3, 4]]print(a[1][0])
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
x = "abcdef"i = "a"while i in x: x = x[:-1] print(i, end = " ")
i i i i i i
a a a a a a
a a a a a
capitalize()
startswith()
pop()
find()
Which of the following will delete key-value pair for key="tiger" in dictionary?
dic={"lion":"'wild","tiger":"'wild",'cat":"domestic","dog":"domestic"}
del dic("tiger")
dic["tiger"].delete()
delete(dic.["tiger'])
del dic["tiger"]
Returns None
Throws a KeyError
Creates a new key with a default value
Crashes the program
print s[0]
print s.lower()
s[1]='r'
print s.strip()
print("xyyzxyzxzxyy".count('xyy', 2, 11))