What will be the output of the following Python code snippet?
print('xyyxyyxyxyxxy'.replace('xy', '12', 100))
xyyxyyxyxyxxy
12y12y1212x12
none of the mentioned
error
Mutable data type
Allows duplicate values
Data type with unordered values
Immutable data type
Error, tuple slicing doesn’t exist
[2,3]
(2,3,4)
(2,3)
>>> 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
list1.insert(3, 5)
list1.insert(2, 5)
list1.add(3, 5)
list1.append(3, 5)
d = {"john":40, "peter":45}print(list(d.keys()))
[“john”, “peter”]
[“john”:40, “peter”:45]
(“john”, “peter”)
(“john”:40, “peter”:45)
Returns None
Throws a KeyError
Creates a new key with a default value
Crashes the program
List of tuple
Tuple of List
Array of Tuples
Invalid Type
str1[ : : -1 ]
str1[ : : 1 ]
str1[ : -1 : -1 ]
None
append()
insert()
index()
remove()
Heeeo
Heelo
Heleo
find()
Both of the above
None of the above
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?
a = [1, 2, 3]a.insert(1, 10)print(a)
[1, 10, 2, 3]
[10, 1, 2, 3]
[1, 2, 10, 3]
Error
['llo']
['hello']
['h', 'e', l', 'l', 'o']
indexing
Replication
concatenation
None of the Above
Sequence value pair
Key value pair
Tuple value pair
Record value pair
list1.remove("hello")
list1.remove(hello)
list1.removeAll("hello")
list1.removeOne ("hello")
25
2
What will be the output of the following Python code?
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]]
count()
strip()
upper()
उपरोकà¥à¤¤ सà¤à¥€
count={} count[(1,2,4)] = 5 count[(4,2,1)] = 7 count[(1,2)] = 6 count[(4,2,1)] = 2 tot = 0 for i in count: tot=tot+count[i] print(len(count)+tot)
17
16
Tuples can’t be made keys of a dictionary
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]
d.delete(“john”:40)
d.delete(“john”)
del d[“john”]
del d(“john”:40)
Array of tuples
List of tuples
Tuples of lists
Invalid type
>>> a={5,6,7}>>> sum(a,5)
5
23
18
Invalid syntax for sum method, too many arguments
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
{ }
set()
[ ]
( )
length
length()
len()
print('abcd'.partition('cd'))
(‘ab’, ‘cd’, ”)
(‘ab’, ‘cd’)
d = {0, 1, 2}for x in d.values(): print(x)
0 1 2
None None None
(1)
(1,)
[1]
{1}
Tuple
Integer
String
List
a = [0, 1, 2, 3]for a[0] in a: print(a[0])
0 1 2 3
0 1 2 2
3 3 3 3
All the above
{}
[]
<>
()
. List is mutable & Tuple is immutable
List is immutable & Tuple is mutable
Both are mutable
Both are immutable
It returns None.
It raises an IndexError
It creates a new element at that index.
It returns an empty list.
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
Dictionary
string = "my name is x"for i in string.split(): 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,
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
[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]
pop()
delete()
remove_last()
delete_last()
a={'B':5,'A':9,'C':7}print(sorted(a))
[‘A’,’B’,’C’]
[‘B’,’C’,’A’]
[5,7,9]
[9,5,7]
print('abcdef12'.replace('cd', '12'))
ab12ef12
abcdef12
ab12efcd
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]]
2445
133
12454
123
s.__len__()
len(s)
size(s)
s.size()
print("xyyzxyzxzxyy".endswith("xyy"))
1
True
3