Logo

Python Questions Set 119:

Quiz Mode

What will be the output of following Python code snippet if x=1?

x<<2

1
2
3
4

Solution:

What will be the output of the following Python code?

print('abcdef'.partition('cd'))

1
2
3
4

Solution:

What will be the output of the following Python code?

>>> a={1,2,3}
>>> {x*2 for x in a|{4,5}}

1
2
3
4

Solution:

Is the following Python code valid?

a={3,4,{7,5}}
print(a[2][0])

1
2
3
4

Solution:

 

What will be the output of the following Python code?

random.seed(3)
random.randint(1,5)
2
random.seed(3)
random.randint(1,5)

1
2
3
4

Solution:

 

What will be the output of the following Python code?

a = ('check',)
n = 2
for i in range(int(n)):
   a = (a,)
   print(a)

1
2
3
4

Solution:

Which of the following rules for naming Python functions is false?

1
2
3
4
5
6

Solution:

After these statements execute, which of the following describes the values that z and y point to?

>>> z = 5

>>> y = z + 1

>>> z = 10

1
2
3
4

Solution:

What will be the output of the following Python code?

class A:
   def __str__(self):
       return '1'
class B(A):
   def __init__(self):
       super().__init__()
class C(B):
   def __init__(self):
       super().__init__()
def main():
   obj1 = B()
   obj2 = A()
   obj3 = C()
   print(obj1, obj2, obj3)

1
2
3
4

Solution: