What will be the output of the following Python code?
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]]
word1="Apple" word2="Apple" list1=[1,2,3] list2=[1,2,3] print(word1 is word2) print(list1 is list2)
True True
False True
False False
True False
places = ['Bangalore', 'Mumbai', 'Delhi'] places1 = places places2 = places[:] places1[1]="Pune" places2[2]="Hyderabad" print(places)
[‘Bangalore’, ‘Pune’, ‘Hyderabad’]
[‘Bangalore’, ‘Pune’, ‘Delhi’]
[‘Bangalore’, ‘Mumbai’, ‘Delhi’]
[‘Bangalore’, ‘Mumbai’, ‘Hyderabad’]
a= [1, 2, 3, 4, 5] for i in range(1, 5): a[i-1] = a[i] for i in range(0, 5): print(a[i],end = " ")
5 5 1 2 3
5 1 2 3 4
2 3 4 5 1
2 3 4 5 5
a=["Apple","Ball","Cobra"] a.sort(key=len) print(a)
[‘Apple’, ‘Ball’, ‘Cobra’]
[‘Ball’, ‘Apple’, ‘Cobra’]
[‘Cobra’, ‘Apple’, ‘Ball’]
Invalid syntax for sort()
What will be the output of the following Python code snippet?
print([i.lower() for i in "HELLO"])
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
‘hello’
[‘hello’]
hello
[x<0 in l]
[x for x<0 in l]
[x in l for x<0]
[x for x in l if x<0]
t=32.00 for x in t: print(x)
[0]
0
[0.00]
Error
[1, 2, 3]
(1, 2, 3)
{1, 2, 3}
{}
print(t[3])
t[3] = 45
print(max(t))
print(len(t))
Tuple
Integer
List
Both tuple and integer
Error, tuple slicing doesn’t exist
[2,3]
(2,3,4)
(2,3)
Array of tuples
List of tuples
Tuples of lists
Invalid type
a=[(2,4),(1,2),(3,9)] a.sort() print(a)
[(1, 2), (2, 4), (3, 9)]
[(2,4),(1,2),(3,9)]
Error because tuples are immutable
Error, tuple has no sort attribute
Mutable data type
Allows duplicate values
Data type with unordered values
Immutable data type
{ }
set()
[ ]
( )
print(len(a))
print(min(a))
a.remove(5)
a[2]=45
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
>>> a={5,6,7} >>> sum(a,5)
5
23
18
Invalid syntax for sum method, too many arguments