Test Your Python Basics: 7 Quick Quiz Questions with Answers
This article presents a short seven‑question Python quiz covering literals, list slicing, the range function, list vs dict differences, semicolon usage, indentation rules, and class constructors, then provides detailed answers and explanations to help beginners assess their foundational knowledge.
Question 1 (Multiple Choice)
Select all that apply: Which literals have a numeric data type (i.e., can be used in arithmetic expressions)?
A. 0xff
B. 99
C. .122
D. "100.2"
Question 2 (Single Choice)
In Python, what does the slice notation list[i:j] do?
A. Sets the value of the i‑th element to j
B. Returns a list slice consisting of elements from index i to j‑1
C. Returns a new list containing only the i‑th and j‑th elements
Question 3 (Single Choice)
What is the purpose of the range function in Python?
A. Returns a list of integers based on a given start value and step (default 1)
B. Defines an iterable series of numbers for loops
C. Returns a list of values of any type within a given interval
Question 4 (Single Choice)
What are the differences and similarities between Python lists and dictionaries?
A. Dictionaries are just another name for lists; there is no difference
B. Both use the [] operator to access elements, but list indices must be integers and sequential
C. Both can use any data type, but dictionaries have dynamic length while lists have fixed length
Question 5 (Single Choice)
Which option correctly describes the use of a semicolon (;) in Python?
A. Separates different statements written on the same line
B. Separates the different parts of a for statement
C. Appears at the end of a line to terminate a statement
D. Links independent clauses in a sentence
Question 6 (Single Choice)
How does Python delimit code blocks, such as the body of an if statement?
A. Each line inside the block is indented more than the surrounding code
B. Code blocks start with begin and end with end C. All lines in a block have the same indentation
D. Code blocks are enclosed in curly braces
Question 7 (Multiple Choice)
Select all valid class constructor definitions in Python:
A. def_Init_(self): B. def_init_(self, var=0): C. def_init_(): D.
def_init_(self, a, b, c):Answers
Question 1
Answer: A, B, C. Python supports integer, floating‑point, and even complex numeric literals; hexadecimal (0xff), decimal (99), and fractional (.122) are all numeric, while a quoted string "100.2" is not.
Question 2
Answer: B. list[i:j] returns a new list containing elements from index i up to, but not including, index j.
Question 3
Answer: A. range(start, stop, step) generates a sequence of integers (often used in for loops) based on the start value, stop value, and step.
Question 4
Answer: B. Both lists and dictionaries use [] for element access, but list indices must be integers and sequential, whereas dictionary keys can be of many immutable types.
Question 5
Answer: A. In Python a semicolon can separate multiple statements on the same line, though its use is rare.
Question 6
Answer: A. Python uses indentation levels to define code blocks; each inner line must be indented more than its containing block.
Question 7
Answer: A, B, D. The constructor method is named __init__; it must receive self as the first parameter and can accept additional arguments.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
