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]]
lst=[3,4,6,1,2] lst[1:2]=[7,8] print(lst)
[3, 7, 8, 6, 1, 2]
Syntax error
[3,[7,8],6,1,2]
[3,4,6,7,8]
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
[1,2,3] [1,2,3,4]
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
def unpack(a,b,c,d): print(a+d) x = [1,2,3,4] unpack(*x)
Error
[1,4]
[5]
5
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 = [1, 5, 7, 9, 9, 1] <br class="blank" />b=a[0] <br class="blank" />x= 0 for x in range(1, len(a)): if a[x] > b: b = a[x] b= x print(b)
3
4
0
a=["Apple","Ball","Cobra"] a.sort(key=len) print(a)
[‘Apple’, ‘Ball’, ‘Cobra’]
[‘Ball’, ‘Apple’, ‘Cobra’]
[‘Cobra’, ‘Apple’, ‘Ball’]
Invalid syntax for sort()
num = ['One', 'Two', 'Three'] for i, x in enumerate(num): print('{}: {}'.format(i, x),end=" ")
1: 2: 3:
Exception is thrown
One Two Three
0: One 1: Two 2: Three
What will be the output of the following Python code snippet?
k = [print(i) for i in my_string if i not in "aeiou"]
prints all the vowels in my_string
prints all the consonants in my_string
prints all characters of my_string that aren’t vowels
prints only on executing print(k)
What is the output of print(k) in the following Python code snippet?
k = [print(i) for i in my_string if i not in "aeiou"] print(k)
all characters of my_string that aren’t vowels
a list of Nones
list of Trues
list of Falses
my_string = "hello world" k = [(i.upper(), len(i)) for i in my_string] print(k)
[(‘HELLO’, 5), (‘WORLD’, 5)]
[(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1), (‘ ‘, 1), (‘W’, 1), (‘O’, 1), (‘R’, 1), (‘L’, 1), (‘D’, 1)]
[(‘HELLO WORLD’, 11)]
none of the mentioned
x = [i**+1 for i in range(3)]; print(x);
[0, 1, 2]
[1, 2, 5]
error, **+ is not a valid operator
error, ‘;’ is not allowed
print([i.lower() for i in "HELLO"])
[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
‘hello’
[‘hello’]
hello
print([i+j for i in "abc" for j in "def"])
[‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]
[[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]
[[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]
[‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]
print([[i+j for i in "abc"] for j in "def"])
print([if i%2==0: i; else: i+1; for i in range(4)])
[0, 2, 2, 4]
[1, 1, 3, 3]
error
[x**-1 for x in [(1, 2, 3)]]
[1/x for x in [(1, 2, 3)]]
[1/x for x in (1, 2, 3)]