What keyword is used to assign a value to a variable in Python?
=
What keyword starts a conditional block?
if
What keyword is used to define a function?
def
What keyword starts a loop that runs a fixed number of times?
for
What type is used to store multiple items in one variable?
list
What is the output of:
x = 5;
y = x;
x = 10;
print(y)
5
What will this print?
x = 4;
if x > 5:
print("Big")
else: print("Small")
Small
What’s the output?
def greet():
return "Hi";
print(greet())
Hi
What will this output?
for i in range(3):
print(i)
0
1
2
What is the index of the first element in a list?
0
What’s the data type of 3.14?
float
How do you combine two conditions using “and”?
if cond1 and cond2:
What does a function return if it has no return statement?
None
How do you stop a loop early?
break
What will this output?
nums = [10, 20, 30]; print(nums[1])
20
What happens if you use a variable before defining it?
NameError
What’s the difference between == and =?
== compares; = assigns.
What’s the difference between parameters and arguments?
Parameters: placeholders in definition;
Arguments: actual values passed in.
How do you skip an iteration of a loop?
continue
How do you add an item to a list?
append()
What will the following code print, and why?
x = 10
def change(x):
x += 5
return x
change(x)
print(x)
10
Write a conditional that prints “Even” if a number n is even, otherwise “Odd”.
if n % 2 == 0:
print("Even")
else:
print("Odd")
Write a function that returns the square of a number.
def square(n):
return n ** 2
What will this code output, and why?
count = 0
for i in range(1, 6):
if i % 2 == 0:
continue
count += i
print(count)
The loop skips even numbers (continue), so it only adds odd numbers (1 + 3 + 5 = 9).
What is the result of list(range(3))?
[0,1,2]