What will be the output of the following Python code?
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
What will be the output of the following Python code snippet?
print('abef'.partition('cd'))
(‘abef’)
(‘abef’, ‘cd’, ”)
(‘abef’, ”, ”)
error
print("xyyzxyzxzxyy".count('yy', 1))
2
0
1
none of the mentioned
d.size()
len(d)
size(d)
d.len ()
It returns None.
It raises an IndexError
It creates a new element at that index.
It returns an empty list.
5
4
None
Error
count()
upper()
strip()
All the above
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
>>> a={1:"A",2:"B",3:"C"}>>> del a
method del doesn’t exist for the dictionary
del deletes the values in the dictionary
del deletes the entire dictionary
del deletes the keys in the dictionary
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]]
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
print('ab cd-ef'.title())
Ab cd-ef
Ab Cd-ef
Ab Cd-Ef
None of the mentioned
numbers = {}letters = {}comb = {}numbers[1] = 56numbers[3] = 7letters[4] = 'B'comb['Numbers'] = numbers comb['Letters'] = lettersprint(comb)
Error, dictionary in a dictionary can’t exist
‘Numbers’: {1: 56, 3: 7}
{‘Numbers’: {1: 56}, ‘Letters’: {4: ‘B’}}
{‘Numbers’: {1: 56, 3: 7}, ‘Letters’: {4: ‘B’}}
What will be the output of the following?
print(sum(1,2,3))
6
3
def f(values): values[0] = 44 v = [1, 2, 3]f(v)print(v)
[1, 44]
[1, 2, 3, 44]
[44, 2, 3]
[1, 2, 3]
White Space
,
e
S
print('Hello World'.istitle())
True
False
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
What does the following code print ?
x = 'mohan'for i in range (len(x)): x[i].upper()print (x)
mohan
MOHAN
None of These
print('abcdefcdghcd'.split('cd', 2))
[‘ab’, ‘ef’, ‘ghcd’]
[‘ab’, ‘efcdghcd’]
[‘abcdef’, ‘ghcd’]
t1=1,2,4
t1=(1,)
t1=tuple(“123”)
All of these
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.
matrix = [[1, 2, 3, 4], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]] for i in range(0, 4): print(matrix[i][1], end = " ")
1 2 3 4
4 5 6 7
1 3 8 12
2 5 9 13
print('abcdef'.partition('cd'))
(‘ab’, ‘ef’)
(‘ab’, ‘cd’, ‘ef’)
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():
What is the output of following code
a=[2,3,4,5]a.insert(3,1)print(a)
[3,2,3,4,5]
[2, 3, 4, 1, 5]
[2, 3,1, 4, 5]
[2, 3,3, 4, 5]
19
18
17
25
Removes an arbitrary element
Removes all the key-value pairs
Removes the key-value pair for the key given as an argument
Invalid method for dictionary
List
Dictionary
Set
None of the Above
a={1:"A",2:"B",3:"C"}for i,j in a.items(): print(i,j,end=" ")
1 A 2 B 3 C
A B C
1:”A” 2:”B” 3:”C”
list1.remove(“hello”)
list1.remove(hello)
list1.removeAll(“hello”)
list1.removeOne(“hello”)
a=[10,23,56,[78]] b=list(a) a[3][0]=95 a[1]=34 print(b)
[10,34,56,[95]]
[10,23,56,[78]]
[10,23,56,[95]]
[10,34,56,[78]]
Returns None
Throws a KeyError
Creates a new key with a default value
Crashes the program
matches a pattern at the start of the string.
matches a pattern at any position in the string.
such a function does not exist
none of the mentioned.
{}
[]
<>
()
print('1.1'.isnumeric())
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
d1={"abc":5,"def":6,"ghi":7}print(d1[0])
abc
{"abc":5}
Tuple
What will be the output?
a={'a':4,'b':6,'a':7}print(a)
{'a': 5, 'b': 6,'a': 7 }
{'a': 7, 'b': 6}
{'a': 5, 'b': 6 }
Key Error
>>> a={5,6,7}>>> sum(a,5)
23
Invalid syntax for sum method, too many arguments
Removes all spaces from the string.
Removes the first and last character of the string.
Removes whitespace from the beginning and end of the string.
Converts the string into a list of characters.
What will be the output of following statement ?
>>>"m"+"n1"
'm+nl'
'mn1'
'm n1'
'm'
anywhere in between the file
End
beginning
second line of the file
print(''.isdigit())
a={1:5,2:3,3:4}a.pop(3) print(a)
{1: 5}
{1: 5, 2: 3}
Error, syntax error for pop() method
{1: 5, 3: 4}
d = {"john":40, "peter":45}print("john" in d)
a={}a['a']=1a['b']=[2,3,4] print(a)
Exception is thrown
{‘b’: [2], ‘a’: 1}
{‘b’: [2], ‘a’: [3]}
{'a': 1, 'b': [2, 3, 4]}
a={1:"A",2:"B",3:"C"}print(a.get(3))
Error, invalid syntax
A
C