Basic Python Quiz

Welcome to the basic Python quiz! Here, we have collected the best 35 multiple-choice questions based on basic Python, which will cover the basic concepts, such as tokens, identifiers, keywords, comments, literals, and escape sequences.

Whether you’re a beginner or preparing for Python coding test, these 35 multiple-choice questions will test your understanding of basic Python. So, are you ready to test your knowledge? Let’s begin from the question number 1. 👇

What are Python tokens?
A. A type of data structure in Python.
B. A built-in function in Python.
C. The smallest individual units in a Python program.
D. A type of exception in Python.
The smallest individual units in a Python program.
Tokens are the basic building blocks of a Python program. They include keywords, identifiers, literals, operators, and punctuation symbols. For example, in the statement x = 10, the tokens are x, =, and 10.
Which of the following is not a token in Python?
A. Keywords
B. Identifiers
C. Statements
D. Literals
Statements
Statements are made up of tokens, but they are not tokens themselves. For example, x = 10 is a statement composed of the tokens x, =, and 10.
What is the purpose of identifiers in Python?
A. To represent reserved words.
B. To name variables, functions, or classes.
C. To define operators.
D. To represent special symbols
To name variables, functions, or classes.
Identifiers are user-defined names used to identify variables, functions, classes, or other objects. For example, in count = 5, count is an identifier.
Which of the following is a valid identifier in Python?
A. 2variable
B. _variable
C. variable-name
D. class
_variable
_variable is valid because it starts with an underscore.
What is the maximum length of an identifier in Python?
A. 32 characters
B. 64 characters
C. 79 characters
D. No fixed limit
No fixed limit
Python does not impose a fixed limit on the length of identifiers, but it is recommended to keep them concise and meaningful.
Which of the following is a keyword in Python?
A. main
B. if
C. return
D. Both (B) and (C)
Both (B) and (C)
if and return are keywords in Python.
How many tokens are in the following code?
x = 10 + 5
print(x)
A. 7
B. 8
C. 9
D. 5
9
Tokens: x, =, 10, +, 5, print, (, x, )
Which symbol is used for single-line comments in Python?
A. //
B. #
C. /*
D. —
#
The # symbol is used for single-line comments. Everything after # symbol on a line is ignored by the Python interpreter.
How do you write a multi-line comment in Python?
A. Using # on each line
B. Using triple quotes (”’ or “””)
C. Using /* and */
D. Both (A) and (B)
Both (A) and (B)
In Python, you can use # for single line comment and triple quotes (”’ or “””) for multi-line comments.
Which of the following is a string literal?
A. 123
B. “Scientech Easy”
C. True
D. 3.14
“Scientech Easy”
A string literal is enclosed in quotes. “Scientech Easy” is a string literal, while 123, True, and 3.14 are numeric and boolean literals.
Which of the following statements is true in Python?
A. Identifiers in Python can start with a digit.
B. 2var and var2 are valid identifiers in Python.
C. Docstrings are a type of comment in Python.
D. Variable and variable are different identifiers in Python.
Variable and variable are different identifiers in Python.
Variable and variable are different identifiers in Python because Python tokens are case-sensitive.
What happens if you write a comment inside triple quotes?
A. It is treated as a comment.
B. It causes an error.
C. It is treated as a string.
D. It causes an error.
It is treated as a string.
Triple quotes (”’ or “””) are used for multi-line strings. If you do not assign them to a variable, they are ignored, but they are not technically comments.
Which of the following lines of code will raise an error?
a) 2name = "Python"  
b) name_2 = "Python"
c) print( [ ] == [ ] )
A. a)
B. b)
C. c)
D. None of them will raise an error.
a)
Line a) will raise an error because identifiers cannot start with a digit.
Identify the literals in the following code.
A. “Alice”
B. 25
C. True
D. All
All
Literals: “Alice”, 25, True.
Which escape sequence is used to represent a newline in Python?
A. \t
B. \n
C. \r
D. \b
\n
The \n escape sequence is used to insert a newline in a string.
What is the output of the following code?
print("Hello\tWorld")
A. HelloWorld
B. Hello\tWorld
C. Hello World
D. Error
Hello World
The \t escape sequence inserts a tab space between Hello and World.
Which escape sequence is used to represent a backslash in Python?
A. \\
B. \/
C. \b
D. \s
\\
The \\ escape sequence is used to insert a literal backslash in a string.
What is the output of the following code?
print("This is a backslash: \\")
A. This is a backslash: \\
B. This is a backslash:
C. This is a backslash: \
D. This is a backslash: /
This is a backslash: \
The \\ escape sequence is interpreted as a single backslash in the output.
What is the output of the following code?
print("Hello\rWorld")
A. Hello World
B. World
C. Hello\rWorld
D. Hello
World
The \r escape sequence is used to represent a carriage return, which moves the cursor to the beginning of the line. Therefore, World overwrites Hello.
Which of the following statement is not correct in Python?
A. Escape sequences are case-sensitive.
B. Identifiers cannot start with a digit.
C. Docstrings are a type of comment in Python.
D. Comments can be placed on the same line as code.
Docstrings are a type of comment in Python.
Docstrings are multi-line strings used for documentation, not comments.
What is the output of the following code?
x = None  
print(type(x))
A. class ‘int’
B. class ‘str’
C. class ‘None’
D. class ‘NoneType’
class ‘NoneType’
None is a special literal representing the absence of a value. Its type is NoneType.
What is the output of the following code?
x = 0b1010  
y = 0o12  
z = 0xA  
print(x, y, z)
A. 10 10 10
B. 9 9 9
C. 11 11 11
D. 10 9 10
10 10 10
0b1010 is a binary literal representing decimal 10. 0o12 is an octal literal representing decimal 10. 0xA is a hexadecimal literal representing decimal 10.
What is the output of the following code?
x = 10
y = "20"
print(x + y)
A. 30
B. 10 + “20”
C. 1020
D. TypeError
TypeError
You cannot add an integer (10) and a string (“20”). This will raise a TypeError.
Which of the following is a valid boolean literal?
A. “True”
B. 1
C. True
D. All of the above
True
Boolean literals in Python are True and False. They must be capitalized.
Which of the following statement is correct in Python?
A. String literals must always be enclosed in double quotes.
B. The literal 0o12 represents a hexadecimal number.
C. The literal 123.45 is of type float.
D. The \\ escape sequence is used to insert a forward slash.
The literal 123.45 is of type float.
Any number with a decimal point is a floating-point literal.
What is the output of the following code?
x = 10
y = float(x)
z = str(y)
print(type(z), z)
A. <class ‘str’=””> 10
B. <class ‘str’=””> 10.0
C. <class ‘str’=””> “10.0”
D. <class ‘float’=””> 10.0
<class ‘str’=””> 10.0
float(x) converts 10 to 10.0. str(y) converts 10.0 to “10.0” (a string).
What is the output of the following code?
x = None
if x:
    print("Hello")
else:
    print("World")
A. Hello
B. World
C. TypeError
D. None of these
World
None evaluates to False in a boolean context.
What is the output of the following code?
x = """Python
is
awesome"""
y = x.replace("\n", " ").upper()
print(y)
A. PYTHON IS AWESOME
B. Python is awesome
C. PYTHON
IS
AWESOME
D. Error
PYTHON IS AWESOME
The variable x is assigned a multi-line string literal. Therefore, it will create a string. The x.replace(“\n”, ” “) method replaces all newline characters (\n) with a space ( ). The upper() method is then called on the modified string, converting all characters to uppercase.
What is the output of the following code?
x = 10
y = "20"
z = x + int(y)
print(z)
A. 30
B. 1020
C. TypeError
D. 10 + “20”
30
int(y) converts the string “20” to an integer 20. x + int(y) results in 10 + 20 = 30.
What is the output of the following code?
x = "Hello\\nWorld"
print(x)
A. Hello
World
B. Hello\nWorld
C. Hello\\nWorld
D. Hello\World
Hello\nWorld
The \\ escape sequence represents a single backslash (\). The string “Hello\\nWorld” is interpreted as Hello\nWorld, where \n is not treated as a newline but as literal characters.
What is the output of the following code?
x = 10
y = "10"
print(type(x) == type(y))
A. True
B. False
C. Error
D. None
False
The type() function returns the type of the variable, and int is not equal to str.
What is the output of the following code?
x = "Hello\tWorld"
y = x.expandtabs(4)
print(y)
A. Hello    World
B. Hello\tWorld
C. Hello World
D. HelloWorld
Hello    World
The \t escape sequence represents a tab character. The x.expandtabs(4) method replaces the tab with 4 spaces, resulting in Hello    World.
What is the output of the following code?
x = True
y = False
z = not x and y
print(z)
A. True
B. False
C. 1
D. 0
False
not x evaluates to False because x is True. False and y evaluates to False (logical AND requires both operands to be True).
What is the output of the following code?
x = "Hello"  # This is a comment
y = "World"
print(x + y)
A. Hello World
B. HelloWorld
C. Hello # This is a commentWorld
D. Error
HelloWorld
The comment after x = “Hello” is ignored by the Python interpreter. The + operator concatenates the strings “Hello” and “World” to produce HelloWorld.
What is the output of the following code?
x = r"Hello\nWorld"
print(x)
A. Hello
World
B. Hello\nWorld
C. Hello\\nWorld
D. Error
Hello\nWorld
The r prefix creates a raw string, where escape sequences will treat as literal characters. \n is not interpreted as a newline but as the literal characters \ and n.

 

DEEPAK GUPTA

DEEPAK GUPTA

Deepak Gupta is the Founder of Scientech Easy, a Full Stack Developer, and a passionate coding educator with 8+ years of professional experience in Java, Python, web development, and core computer science subjects. With strong expertise in full-stack development, he provides hands-on training in programming languages and in-demand technologies at the Scientech Easy Institute, Dhanbad.

He regularly publishes in-depth tutorials, practical coding examples, and high-quality learning resources for both beginners and working professionals. Every article is carefully researched, technically reviewed, and regularly updated to ensure accuracy, clarity, and real-world relevance, helping learners build job-ready skills with confidence.