1 / 30

If you assign a new value to an existing variable in Python, what happens to the old value?

When you reassign a value to a variable, the old value is replaced by the new value. Python's garbage collector will eventually reclaim the memory used by the old value if it's no longer referenced elsewhere.

2 / 30

What is the output of:

x = 10
y = 3
print(x % y * 2 ** 2)

3 / 30

What will this code print:

x = 100
print(isinstance(x, int) and x > 0 and x % 2 == 0)

4 / 30

What will this code print:

x = 15 # 0b1111
y = 10 # 0b1010
print(x & y, x | y, x ^ y)

5 / 30

Which of the following is a valid variable name in Python?

6 / 30

What is the main purpose of using comments in Python code?

Comments are for humans, not the computer. They are used to clarify what the code is doing, why it's doing it, and to provide context for other developers (or your future self) who might read the code. Good comments make the code easier to understand and maintain.

7 / 30

Given the following lists:

names = ["Alice", "Bob", "Charlie"]
ages = [25, 30, 28]

8 / 30

What is the result of:

x = 300
y = 300
z = 300
print(x is y, y is z)

9 / 30

How would you remove all the items from the d dictionary?

d = {'A' : 1, 'B' : 2, 'C' : 3}

10 / 30

What will this code print:

x = 10
x += x //= 2
print(x)

11 / 30

What will be printed:

x = [1, 2, 3]
y = [1, 2, 3]
z = x
print(x == y, x is y, x is z)

12 / 30

What will be the output of the following code snippet?

a = [1, 2, 3, 4, 5, 6, 7, 8, 9]

print(a[::2])

13 / 30

What will be the output of the following code snippet?

a = [1, 2, 3, 4, 5, 6, 7, 8, 9]

print(a[::2])

14 / 30

What is the result of:

print(~0, ~-1, ~1)

15 / 30

What is the output of:

x = [1]
x *= 2
x[0] += x[1]
print(x)

16 / 30

What does range(2, 10, 2) generate?

17 / 30

What is the output of:

s = 'Python'
print(s.center(10, '*'), len(s.center(10, '*')))

18 / 30

What will be printed:

print(int('0b1010', 2), int('0o12', 8), int('0xA', 16))

19 / 30

What will this code print:

x = 1
del x
try:
print(x)
except NameError:
print('Error')

20 / 30

What will this code print:

print(bool(0) == False, 0 == False, bool(0) is False)

21 / 30

What is the output of:

print(format(20, 'b'), format(20, 'o'), format(20, 'x'), format(20, 'd'))

22 / 30

If range(5) is used in a for loop, how many times will the loop body be executed?

23 / 30

What will this code print:

x = 5
y = -x
z = +y
print(x + y + z)

24 / 30

What will be the output of the following code snippet?

d = {}

d[1] = 1

d['1'] = 2

d[1] += 1

sum = 0

for k in d:

sum+= d[k]

print(sum)

25 / 30

What will be printed:

x = 0xFF
y = int('FF', 16)
print(x == y, x)

26 / 30

What is the output of:

print('abc' < 'abd', 'abc' <= 'abc', 'Z' > 'a')

27 / 30

What will be printed:

x = 'A'
x *= 2
x += 'B' * 3
print(x)

28 / 30

What will be the output of the following Python code?

x = 5
while x > 0:
print(x)
x -= 1
else:
print("Loop finished")

The loop prints the value of x as long as x is greater than 0. The else block associated with the while loop is executed only when the loop finishes normally (i.e., the condition becomes False), not if it's terminated by a break statement.

29 / 30

What will this code print:

x = 'abc' * -1
print(len(x))

30 / 30

What is the output of:

x = 1.5e3
y = 15e2
z = 1500.0
print(x == y == z)

Your score is