What will be printed?
a = [1, 2, 3]print(a * 2)
[2, 4, 6]
[1, 2, 3, 1, 2, 3]
Error
[1, 4, 9]
d.size()
len(d)
size(d)
d.len ()
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)
What will be the output of the following Python code?
names = ['Amir', 'Bear', 'Charlton', 'Daman']print(names[-1][-1])
A
Daman
n
wd[4:]
wd[:4]
wd[-5:]
wd[:-4]
[3, 4, 5, 20, 5, 25, 1, 3, 34, 5]
[1, 3, 3, 4, 5, 5, 20, 25, 34, 5]
[25, 20, 5, 5, 4, 3, 3, 1, 34, 5]
[1, 3, 4, 5, 20, 5, 25, 3, 34, 5]
string = "my name is x"for i in string: print (i, end=", ")
m, y, , n, a, m, e, , i, s, , x,
m, y, , n, a, m, e, , i, s, , x
my, name, is, x,
error
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]))
1
2
4
5
Mutable data type
Allows duplicate values
Data type with unordered values
Immutable data type
anywhere in between the file
End
beginning
second line of the file
Clears all key-value pairs
Updates a specific key
Merges another dictionary into the current one
Removes all values
slicer
Slicing
Membership
None of these-
Sorts array
Reverses array
Deletes elements
Returns copy only
>>> a={5,6,7}>>> sum(a,5)
23
18
Invalid syntax for sum method, too many arguments
remove
pop
discard
dispose
{1: ‘A’, 2: ‘B’}
dict([[1,”A”],[2,”B”]])
{1,”A”,2”B”}
{ }
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 Python code snippet?
a = [0, 1, 2, 3]for a[-1] in a: print(a[-1])
0 1 2 3
0 1 2 2
3 3 3 3
print('abef'.partition('cd'))
(‘abef’)
(‘abef’, ‘cd’, ”)
(‘abef’, ”, ”)
d = {0: 'a', 1: 'b', 2: 'c'}for x in d.keys(): print(d[x])
0 1 2
a b c
0 a 1 b 2 c
none of the mentioned
example = "snow world"example[3] = 's'print (example)
snow
snow world
snos world
print('abc'.islower())
True
False
None
x = ['ab', 'cd']for i in x: i.upper() print(x)
[‘ab’, ‘cd’]
[‘AB’, ‘CD’]
[None, None]
print('ab cd ef'.title())
Ab cd ef
Ab cd eF
Ab Cd Ef
None of the mentioned
d = {0: 'a', 1: 'b', 2: 'c'}for x in d.values(): print(x)
empty_tuple = ()
empty_tuple = tuple()
empty_tuple = []
Both A and B
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’}}
print('abcdefcdghcd'.split('cd', 0))
[‘abcdefcdghcd’]
‘abcdefcdghcd’
print('1Rn@'.lower())
1rn@
rn
r
What will be the result?
a = [1, 2, 3]print(a[1:])
[1]
[2, 3]
[1, 2]
islower()
isupper()
Islower()
print s[0]
print s.lower()
s[1]='r'
print s.strip()
values = [[3, 4, 5, 1], [33, 6, 1, 2]]v = values[0][0]for row in range(0, len(values)): for column in range(0, len(values[row])): if v < values[row][column]: v = values[row][column]print(v)
3
6
33
print("xyyzxyzxzxyy".endswith("xyy"))
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
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
Concatenation
Deletion of elements
Iteration
Returns None
Throws a KeyError
Creates a new key with a default value
Crashes the program
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”
print("abcdef".find("cd"))
>>>max("what are you")
what
y
a
list1 = [1, 3]list2 = list1list1[0] = 4print(list2)
[1, 3]
[4, 3]
[1, 4]
[1, 3, 4]
print('cd'.partition('cd'))
(‘cd’)
(”)
(‘cd’, ”, ”)
(”, ‘cd’, ”)
myList = [1, 5, 5, 5, 5, 1]max = myList[0]indexOfMax = 0for i in range(1, len(myList)): if myList[i] > max: max = myList[i] indexOfMax = i print(indexOfMax)
What will be the output?
t = (1, 2, 3)t[1] = 5print(t)
(1, 5, 3)
(1, 2, 3)
x = "abcdef" i = "a" while i in x[:-1]: print(i, end = " ")
a a a a a
a a a a a a
a a a a a a … infinite Time
what will the output of following code
my_string="Hello,world"print(my_string[-6:-1])
,worl
worl
world
oworld
d = {"a": 1, "b": 2}print(2 in d)
KeyError
copy = list(original)
copy = original[:]
copy = original.copy()
All of the above
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]