What will be the output of the following Python code?
values = [[3, 4, 5, 1], [33, 6, 1, 2]]v = values[0][0]for lst in values: for element in lst: if v > element: v = elementprint(v)
1
3
5
6
s2.issubset(s1)
s2.issuperset(s1)
s1.issuperset(s2)
s1.isset(s2)
a= [1, 2, 3, 4, 5]for i in range(1, 5): a[i-1] = a[i]for i in range(0, 5): print(a[i],end = " ")
5 5 1 2 3
5 1 2 3 4
2 3 4 5 1
2 3 4 5 5
More than one key can have the same value
The values of the dictionary can be accessed as dict[key]
Values of a dictionary must be unique
Values of a dictionary can be a mixture of letters and numbers
It returns None.
It raises an IndexError
It creates a new element at that index.
It returns an empty list.
a=[13,56,17] a.append([87]) a.extend([45,67]) print(a)
[13, 56, 17, [87], 45, 67]
[13, 56, 17, 87, 45, 67]
[13, 56, 17, 87,[ 45, 67]]
[13, 56, 17, [87], [45, 67]]
print('Hello!2@#World'.istitle())
True
False
None
error
25
What will be the output of the following Python code snippet?
print('HelloWorld'.istitle())
Error
String
List
Tuple
Dictionary
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)
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
What will be the output of the following Python expression?
x=24//6%3, 24//4//2 print(x)
(1,3)
(0,3)
(1,0)
(3,1)
print('abcdef12'.replace('cd', '12'))
ab12ef12
abcdef12
ab12efcd
none of the mentioned
mylist=list("a#b#c#d".split('#'))print(mylist)
[‘a’, ‘b’, ‘c’, ‘d’]
[‘a b c d’]
[‘a#b#c#d’]
[‘abcd’]
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]def ttt(m): v = m[0][0] for row in m: for element in row: if v < element: v = element return vprint(ttt(data[0]))
2
4
What will be the output of the following code snippet?
a=[1,2,3,4,5,6,7,8,9]a[::2]=10,20,30,40,50,60print(a)
ValueError: attempt to assign sequence of size 6 to extended slice of size 5
[10, 2, 20, 4, 30, 6, 40, 8, 50, 60]
[1, 2, 10, 20, 30, 40, 50, 60]
[1, 10, 3, 20, 5, 30, 7, 40, 9, 50, 60]
print(max("what are you"))
u
t
y
print('abcdefcdghcd'.split('cd'))
[‘ab’, ‘ef’, ‘gh’]
[‘ab’, ‘ef’, ‘gh’, ”]
(‘ab’, ‘ef’, ‘gh’)
(‘ab’, ‘ef’, ‘gh’, ”)
a=dict()print(a[1])
An exception is thrown since the dictionary is empty
‘ ‘
0
What is the output of the following code:
L=['a','b','c','d']print ( "".join(L))
abcd
[‘a’,’b’,’c’,’d’]
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]]
def m(list): v = list[0] for e in list: if v < e: v = e return v values = [[3, 4, 5, 1], [33, 6, 1, 2]] for row in values: print(m(row), end = " ")
3 33
1 1
5 6
5 33
Mutable data type
Allows duplicate values
Data type with unordered values
Immutable data type
What will be the output of the following code?
a=((0,2,3,4)[1:-2])print(a)
(3,)
(2, )
(1,)
(0,)
delete all the trailing whitespace characters
delete all the leading whitespace characters
delete all the leading and trailing whitespace characters
delete upper case characters
s[]
s.getitem(3)
s.__getitem__(3)
s.getItem(3)
list1=[1,3]list2=list1list1[0]=4print(list2)
[1, 4]
[1,3, 4]
[4,3]
[1,3]
>>> 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
numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
numberGames[(1,2)] = 12
sum = 0
for k in numberGames:
sum += numberGames[k]
print len(numberGames) + sum
30
24
33
12
print('abef'.replace('cd', '12'))
abef
print('ab'.isalpha())
a=["Apple","Ball","Cobra"]a.sort(key=len)print(a)
[‘Apple’, ‘Ball’, ‘Cobra’]
[‘Ball’, ‘Apple’, ‘Cobra’]
[‘Cobra’, ‘Apple’, ‘Ball’]
Invalid syntax for sort()
More than one key isn’t allowed
Keys must be immutable
Keys must be integers
When duplicate keys encountered, the last assignment wins
set
tuple
string
None of These
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
list1.sum(5)
list1.add(5)
listl.append(5)
list1.addelement(5)
What does the following code print ?
x = 'mohan'for i in range (len(x)): x[i].upper()print (x)
mohan
MOHAN
print('abcdefcdgh'.partition('cd'))
(‘ab’, ‘cd’, ‘ef’, ‘cd’, ‘gh’)
(‘ab’, ‘cd’, ‘efcdgh’)
(‘abcdef’, ‘cd’, ‘gh’)
getkeys ()
key()
keys()
x = "abcdef"i = "a"while i in x: x = x[1:] print(i, end = " ")
a a a a a a
a
no output
slicer
Slicing
Membership
None of these-
print("Welcome to Python".split())
[“Welcome”, “to”, “Python”]
(“Welcome”, “to”, “Python”)
{“Welcome”, “to”, “Python”}
“Welcome”, “to”, “Python”
a={1:"A",2:"B",3:"C"}print(a.items())
Syntax error
dict_items([(‘A’), (‘B’), (‘C’)])
dict_items([(1,2,3)])
dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])
White Space
,
e
S
Array of tuples
List of tuples
Tuples of lists
Invalid type
a={1:"A",2:"B",3:"C"}print(a.get(3))
Error, invalid syntax
A
C
print('cd'.partition('cd'))
(‘cd’)
(”)
(‘cd’, ”, ”)
(”, ‘cd’, ”)
print('xyxxyyzxxy'.lstrip('xyy'))
zxxy
xyxxyyzxxy
xyxzxxy
a={1:"A",2:"B",3:"C"}a.setdefault(4,"D") print(a)
{1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’}
[1,3,6,10]