Logo

Python Questions Set 133:

Quiz Mode

Deduce the output of the following code:


def fun(n):

    while(n<5):

        n+=1

    print(n)


fun(0)

Solution:

Consider the following Python code:

values = [1, 2, 1]
a, b, c = values
print(a)

1
2
3
4

Solution:

 

import datetime
dt_1 = datetime.datetime.today()
dt_2 = datetime.datetime.now()
print(dt_1)
print(dt_2)

1
2

Solution:

Deduce the output of the following code:

n= {1,1,1,2,2,4,5,6,7,8}

n&={1,2,4,5}

print(list(list(filter(lambda x: x>1,n))))

Solution:

What is the output of the code shown below?

def f(x): yield x+1 print("test") yield x+2

g = f(9)

1
2
3
4

Solution:

What is the output of the given code?


def swap(x,y):

    temp=x

    x=y

    y=temp

    

x=2

y=3

swap(x,y)

print(x)

print(y)

1
2

Solution:

What is the output of the following code?


d={'a':1,'b':2,'c':3,'d':4}

for i in d:

    print(i)

1
2
3
4

Solution:

What is the output of the following code?

def numbers(x,y):

       print(x)

       return

       print(y)

       return

print(numbers(4,5))

1
2
3
4

Solution:

What will be the output of the following Python code?

>>> a={5,6,7,8}
>>> b={7,8,10,11}
>>> a^b

1
2
3
4

Solution:

What is the output of the following code?

a = {22, 26, 21, 29, 24}
a.add(25)
a.update([33, 31, 32])
print(a)
a.remove(21)
a.discard(26)
print(a)

1
2
3
4

Solution: