Font size
WorksheetsPython Basics Quiz
Total questions: 20
Worksheet time: 13mins
What is a variable in Python?
A reserved keyword that cannot be changed.
A container that stores data values, which can be reassigned.
A function that performs calculations.
A data type like int or str.
How do you declare a variable in Python?
By using the 'var' keyword, like var x = 5.
By assigning a value directly, like x = 5.
By specifying the type first, like int x = 5.
Variables must be declared without assignment.
What data type is used for whole numbers in Python?
float
str
int
bool
Which of the following is a floating-point number?
42
"3.14"
3.14
True
What does the type() function do?
Changes the type of a variable.
Returns the data type of a value or variable.
Prints the value of a variable.
Assigns a new value to a variable.
What is the output of print(type("Hello"))?
Which operation can you perform on two integers?
Concatenation using +
Addition using +
Repetition using /
Type conversion using type()
What happens when you try to add a string and an integer, like "Age: " + 25?
It works and outputs "Age: 25"
It raises a TypeError.
It converts the int to str automatically.
It outputs 25Age:
How do you concatenate two strings?
Using - operator
Using + operator
Using * operator
Using / operator
What is the data type for True or False values?
int
str
float
bool
Which function converts a string to an integer?
str()
int()
float()
bool()
What are valid variable naming rules in Python? (Select the correct statement)
Can start with a number, like 1var.
Must start with a letter or underscore, no spaces, case-sensitive.
Can use special characters like @ or $.
Must be all uppercase.
What is the output of x = 10; x = 20; print(x)?
10
20
Error
30
How do you check if a variable is a boolean?
Using isinstance(var, bool)
Using type(var) = bool
Using var == True or False
Using bool(var)
What does "dynamic typing" mean in Python?
You must declare types explicitly.
Types are inferred at runtime and can change.
Variables can't change types.
All variables are strings.
What is the result of 10 / 2 in Python?
5 (int)
5.0 (float)
Error
5.
How can you assign multiple variables at once?
a = b = c = 5
a, b, c == 5
a; b; c = 5
Only one at a time.
What type is returned by input() function?
int
float
str
bool
Which of the following causes a NameError?
print(my_var) after my_var = 10
print(my_var) before assigning my_var
my_var = "10" + 10
type(10)
What is None in Python?
A boolean value like False.
A special type representing absence of value.
An integer zero.
An empty string.
