# Python quiz questions

• 1.

How many times f() will be printed?

``````def f():
print("f()")
return 1

a = 0<f()<2
a = 0<f() and f()<2``````

1. One

2. Two

3. Three

4. Four

• 2.

a = ?

``a = 1 < 2 == 2 > 1 in [1,2,3] < [2,3,4,5] != 1``

1. True

2. False

3. It causes SyntaxError

• 3.

a = ?

``a = 3 < 5 < 7``

1. True

2. False

3. It causes SyntaxError

• 4.

a = ?

``````def f(a=[]):
a.append(1)
return a

a=(f(),f())``````

1. (, )

2. (, [1,1])

3. ([1,1], [1,1])

• 5.

What does this function return?

``````def f(a,b):
return a,b

f(**{'b':2,'a':1})``````

1. (1, 2)

2. (2, 1)

3. It causes TypeError: f() got an unexpected keyword argument

• 6.

Is this syntax valid?

``````def f(a):
pass

f(a for a in [1,2])``````

1. Yes

2. No, it causes SyntaxError: Generator expression must be parenthesized

• 7.

What will be printed:

``````def f(a, b):
print(a, b)

f(b=1, *(2,))``````

1. 2 1

2. 1 2

3. This code causes TypeError

• 8.

a = ?

``a = { b : b+10 for b in range(10) }``

1. It causes a SyntaxError

2. {0: 9}

3. {0: 10, 1: 11, 2: 12, 3: 13, 4: 14, 5: 15, 6: 16, 7: 17, 8: 18, 9: 19}

• 9.

Is this syntax valid?

``a = { i,j for i in range(0,10,2) for j in range(1,10,2)}``

1. Yes

2. No

• 10.

Is this syntax valid?

``a = { i for i in range(0,10,2) }``

1. Yes

2. No

• 11.

a = ?

``a = -4 // 1.5``

1. 2.0

2. 3.0

3. -2.0

4. -3.0

• 12.

What is the result of a

``a = -4 % 1.5``

1. 0.5

2. 1.0

3. -0.5

4. -1.0

• 13.

The operations |, ^ and & ..

1. .. have same priority

2. .. not have same priority

• 14.

What the will be in a?

``a = -1 ** 2``

1. -1

2. 1

• 15.

What is the type of a?

``a = (b for b in [1,2])``

1. tuple

2. generator

• 16.

What is the type of a?

``a = {}``

1. dict

2. set

• 17.

What is the type of a?

``a = {1,2:3}``

1. dict

2. set

3. It causes SyntaxError

• 18.

What is the type of a?

``a = 10.0//5``

1. float

2. int

• 19.

What is the type of a(Python 3)?

``a = 10/5``

1. float

2. int

• 20.

What is the type of b(Python 3)?

``````a = -1
b = a ** 0.5``````

1. float

2. complex

3. int

4. str