A. To permanently store data on the hard drive
B. To serve as a named reference to a value stored in memory
C. To define the syntax rules of the language
D. To compile Python code into machine language
CORRECT ANSWER: B. To serve as a named reference to a value stored in memory
Rationale: A variable in Python is a named reference that points to an object stored in
memory. It allows a programmer to store, retrieve, and manipulate data throughout a
program. Variables do not permanently store data on disk (that is file I/O) and are not
involved in language syntax definition or compilation.
Question 2: Which of the following is a valid Python variable name?
A. 2nd_place
B. total-score
C. _user_name
D. class
CORRECT ANSWER: C. _user_name
Rationale: Python variable names must begin with a letter or an underscore, may
contain letters, digits, and underscores, and cannot be a reserved keyword.
"2nd_place" begins with a digit, "total-score" contains a hyphen, and "class" is a
reserved keyword.
Question 3: What data type does the expression type() return in Python 3?
A. int
B. float
C. str
D. bool
CORRECT ANSWER: B. float
Rationale: In Python 3, the single forward slash / performs true division and always
returns a float, even when the result is a whole number. evaluates to 5.0, so type()
returns float. The // operator would return an integer.
Question 4: Which of the following is an immutable data type in Python?
,A. list
B. dictionary
C. set
D. tuple
CORRECT ANSWER: D. tuple
Rationale: A tuple is immutable, meaning its contents cannot be changed after
creation. Lists, dictionaries, and sets are mutable and can be modified after they are
created. Immutability means no item assignment, appending, or removal is permitted.
Question 5: What is the result of the expression 7 // 2?
A. 3.5
B. 3
C. 4
D. 1
CORRECT ANSWER: B. 3
Rationale: The // operator performs floor division, which divides and then rounds down
to the nearest whole number. 7 // 2 equals 3.5, which floors to 3. The % operator would
return the remainder 1.
Question 6: What is the result of the expression 2 ** 3?
A. 6
B. 8
C. 9
D. 5
CORRECT ANSWER: B. 8
Rationale: The ** operator performs exponentiation. 2 ** 3 means 2 raised to the power
of 3, which equals 8. The * operator would give 6, and + would give 5.
Question 7: Which operator is used to check equality in Python?
A. =
B. ==
C. !=
D. <=
,CORRECT ANSWER: B. ==
Rationale: The == operator compares two values for equality and returns a Boolean. The
single = is the assignment operator. The != operator checks inequality, and <= checks
less-than-or-equal-to.
Question 8: What is the output of the following code? x = 5; y = 2; print(x % y)
A. 2.5
B. 2
C. 1
D. 0
CORRECT ANSWER: C. 1
Rationale: The % operator returns the remainder of integer division. 5 divided by 2
equals 2 with a remainder of 1, so print(x % y) outputs 1. The // operator would return 2.
Question 9: Which of the following correctly creates a string in Python?
A. name = 'Alice'
B. name = Alice
C. name = @Alice@
D. name = [Alice]
CORRECT ANSWER: A. name = 'Alice'
Rationale: Strings in Python are created by enclosing characters in single quotes,
double quotes, or triple quotes. Option B would attempt to reference an undefined
variable, Option C uses invalid symbols, and Option D creates a list.
Question 10: What is the result of len("Python")?
A. 5
B. 6
C. 7
D. Error
CORRECT ANSWER: B. 6
Rationale: The len() function returns the number of characters in a string, including
spaces. "Python" has six characters: P, y, t, h, o, n. Indexing is zero-based, but len()
returns the total count.
, Question 11: What does the following code output? print("Hello" + "World")
A. Hello World
B. HelloWorld
C. Hello+World
D. Error
CORRECT ANSWER: B. HelloWorld
Rationale: The + operator concatenates strings without adding a space. To include a
space, the programmer must explicitly include it, as in "Hello " + "World". The output is
HelloWorld.
Question 12: What is the output of print("ab" * 3)?
A. ababab
B. ab3
C. ab ab ab
D. Error
CORRECT ANSWER: A. ababab
Rationale: The * operator repeats a string the specified number of times. "ab" * 3
produces "ababab". No spaces are inserted between repetitions.
Question 13: What is the correct way to convert the string "42" to an integer?
A. int("42")
B. str(42)
C. float("42")
D. integer("42")
CORRECT ANSWER: A. int("42")
Rationale: The int() function converts a string or float to an integer. str() converts to a
string, float() converts to a float, and integer() is not a built-in Python function.
Question 14: Which of the following is the correct syntax for an if statement in
Python?
A. if x > 5 { print("yes") }
B. if x > 5: print("yes")