What will be the output of the following Python code?
str1="helloworld"print(str1[::-1])
dlrowolleh
hello
world
helloworld
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.
a={5,5,6,7}
a={5,6,7}
Error as there is no add function for set data type
Error as 5 already exists in the set
print("xyyzxyzxzxyy".count('yy', 1))
2
0
1
none of the mentioned
4
[2, 6, 4]
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
names = ['Amir', 'Bear', 'Charlton', 'Daman']print(names[-1][-1])
A
Daman
Error
n
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.
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
What will be the output of the following Python code snippet?
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’}}
Clears all key-value pairs
Updates a specific key
Merges another dictionary into the current one
Removes all values
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]
What is the output of the following program:
print ("Hello World"[::-1])
dlroW olleH
Hello Worl
D
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
[0, 1, 2, 3]
[0, 1, 2, 3, 4]
[0.0, 0.5, 1.0, 1.5]
[0.0, 0.5, 1.0, 1.5, 2.0]
x = 'abcd'for i in range(len(x)): x[i].upper()print (x)
abcd
ABCD
print('xyxxyyzxxy'.lstrip('xyy'))
zxxy
xyxxyyzxxy
xyxzxxy
print("xyyzxyzxzxyy".endswith("xyy", 0, 2))
True
False
What is the correct command to shuffle the following list?
fruit=['apple', 'banana', 'papaya', 'cherry']
fruit.shuffle()
shuffle(fruit)
random.shuffle(fruit)
random.shuffleList(fruit)
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
print(len(a))
print(min(a))
a.remove(5)
a[2]=45
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]
print('1Rn@'.lower())
1rn@
rn
r
list1.remove("hello")
list1.remove(hello)
list1.removeAll("hello")
list1.removeOne ("hello")
('abc’)
('a', 'b', 'c’)
['a', 'b', 'c’]
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():
2445
133
12454
123
getkeys()
key()
keys()
. List is mutable & Tuple is immutable
List is immutable & Tuple is mutable
Both are mutable
Both are immutable
startswith()
startswith_prefix()
startswithwith()
startswiths()
a=["Apple","Ball","Cobra"]a.sort(key=len)print(a)
[‘Apple’, ‘Ball’, ‘Cobra’]
[‘Ball’, ‘Apple’, ‘Cobra’]
[‘Cobra’, ‘Apple’, ‘Ball’]
Invalid syntax for sort()
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]))
5
print('ab cd ef'.title())
Ab cd ef
Ab cd eF
Ab Cd Ef
None of the mentioned
Error, tuple slicing doesn’t exist
[2,3]
(2,3,4)
(2,3)
pop()
delete()
remove_last()
delete_last()
count()
strip()
upper()
उपरोकà¥à¤¤ सà¤à¥€
len()
index()
find()
list1 = [11, 2, 23]list2 = [11, 2, 2]print(list1 < list2)
None
t1=1,2,4
t1=(1,)
t1=tuple(“123”)
All of these
What will be the output of following statement ?
>>>"m"+"n1"
'm+nl'
'mn1'
'm n1'
'm'
d.delete(“john”:40)
d.delete(“john”)
del d[“john”]
del d(“john”:40)
dictionary()
set()
tuple()
list()
set
tuple
string
None of These
List
Dictionary
Set
None of the Above
i.__add(j)
i.__add__(j)
i.__Add(j)
i.__ADD(j)
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
print('ab'.isalpha())
list1=[1,3]list2=list1list1[0]=4print(list2)
[1, 4]
[1,3, 4]
[4,3]
[1,3]
print('Hello World'.istitle())
insert()
append()
extend()
add()