Q. Predict the output:-


(a)

lst = [1, 2, 3]

myvar = lst[0]

lst[0] = 18

print (lst)

print (myvar)


(b)

myvar = 18

lst = [myvar, 2, 3]

myvar = 22

print (lst)

print (myvar)


(c)

a = [1, 2, [3, 4], 5]

print(len(a))

print(-1 * len(a))

print(a[2], len(a[2]))


(d)

a = [1, 2, 3]

a[2]=0

a[a[2]] = 5

a[1:2] = []

print(a)


(e)

a = [ 55, 44, 33, 22, 11, 0]

print(a[0] )

print(a[-1] )

print(a[a[0]] )

print( a[a[-1]])

print(a[a[a[a[2]+1]]] )


(f)

for x in [1, 2]:

    for y in [3, x]:

        print (x, y)



Answer =

Output:-

(a)
[18, 2, 3]
1
>>>

(b)
[18, 2, 3]
22
>>>

(c)
4
-4
[3, 4] 2
>>>

(d)
[5, 0]
>>>

(e)
55
0
Traceback (most recent call last):
  File "C:\Desktop\Q7.py", line 4, in <module>
    print(a[a[0]] )
IndexError: list index out of range
>>>

(f)
1 3
1 1
2 3
2 2
>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post