What will be the output of the following Python code?
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]
0
4
1
2
[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]
print(list1[0])
print(list1[:2])
print(list1[:-2])
all of the mentioned
It returns None.
It raises an IndexError
It creates a new element at that index.
It returns an empty list.
x = ['ab', 'cd']for i in x: i.upper() print(x)
[‘ab’, ‘cd’]
[‘AB’, ‘CD’]
[None, None]
none of the mentioned
myList = [1, 2, 3, 4, 5, 6]for i in range(1, 6): myList[i - 1] = myList[i] for i in range(0, 6): print(myList[i], end = " ")
2 3 4 5 6 1
6 1 2 3 4 5
2 3 4 5 6 6
1 1 2 3 4 5
. List is mutable & Tuple is immutable
List is immutable & Tuple is mutable
Both are mutable
Both are immutable
list.contains(value)
list.index(value)
value in list
Built in
List
Tuple
Derived data
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]
list1 = list()
list1 = []
list1 = list([1, 2, 3])
a=["Apple","Ball","Cobra"]a.sort(key=len)print(a)
[‘Apple’, ‘Ball’, ‘Cobra’]
[‘Ball’, ‘Apple’, ‘Cobra’]
[‘Cobra’, ‘Apple’, ‘Ball’]
Invalid syntax for sort()
[3, 5, 20, 5, 25, 1, 3]
[1, 3, 4, 5, 20, 5, 25]
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
List is mutable & Tuple is immutable
Both List and Tuple are Mutable
Both List and Tuple are Immutable
What is the output of the following code:
L=['a','b','c','d']print ( "".join(L))
Error
None
abcd
[‘a’,’b’,’c’,’d’]
list1 = [1, 3]list2 = list1list1[0] = 4print(list2)
[1, 3]
[4, 3]
[1, 4]
[1, 3, 4]
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
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]]
list=()
list.null
null.list
list=[]
list1=[1,3]list2=list1list1[0]=4print(list2)
[1,3, 4]
[4,3]
[1,3]
i.__add(j)
i.__add__(j)
i.__Add(j)
i.__ADD(j)
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)
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
error
list1 = [11, 2, 23]list2 = [11, 2, 2]print(list1 < list2)
True
False
[2, 6, 4]
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
Heeeo
Heelo
Heleo
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)
names = ['Amir', 'Bear', 'Charlton', 'Daman']print(names[-1][-1])
A
Daman
n
list1.addEnd (5)
list1.addLast (5)
list1.append (5)
list1.add(5)
input(“Enter a string”)
eval(input(“Enter a string”))
enter(“Enter a string”)
eval(enter(“Enter a string”))
9
15
[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]
list1.shuffle()
shuffle(list1)
random.shuffle(list1)
random.shuffleList(list1)
for i in [1, 2, 3, 4][::-1]: print (i)
1 2 3 4
4 3 2 1
What is the output of the following code?
list1=[2, 33, 222, 14, 25]print(list1[ : -1 ])
[2, 33, 222, 14]
25
[25, 14, 222, 33, 2]
['llo']
['hello']
['h', 'e', l', 'l', 'o']
None of the above
arr[-2]
arr[2]
arr[-1]
arr[1]
2445
133
12454
123
list1.insert(3, 5)
list1.insert(2, 5)
list1.add(3, 5)
list1.append(3, 5)
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
list1.remove(“hello”)
list1.remove(hello)
list1.removeAll(“hello”)
list1.removeOne(“hello”)
mylist=list("a#b#c#d".split('#'))print(mylist)
[‘a’, ‘b’, ‘c’, ‘d’]
[‘a b c d’]
[‘a#b#c#d’]
[‘abcd’]
Returns None
Throws a KeyError
Creates a new key with a default value
Crashes the program