True or false: In Python, a variable name can refer first to an integer and later to a string without declaring a new variable type.
2 Variables and Data Types Online Quiz Questions
Use this free practice quiz with 20 questions to review 2 Variables and Data Types, test your knowledge, and prepare for your next test or exam.
Which proposed Python name is valid and can be used as an ordinary identifier?
- A
2nd_place
- B
place_2
- C
place-two
- D
class
What Python type does the expression 17 / 2 produce?
What is the value of 17 // 5 in Python?
- A
2
- B
3
- C
3.4
- D
4
True or false: In Python, int(-7.9) returns -8 because the value is rounded to the nearest integer.
- A
True
- B
False
What integer does len("Python") return?
Select all operations that are supported for Python strings.
- A
"Py" + "thon" - B
"ha" * 3 - C
word[0] = "p" - D
word[1:4]
Select all values that Python treats as false in a Boolean context.
- A
False - B
None - C
"0" - D
0 - E
""
Given the Python statements width = 8, height = 5, and area = width * height, what value does area refer to?
- A
40
- B
13
- C
35
- D
85
True or false: In Python, int(7.9) evaluates to 7.
- A
True
- B
False
Which expression correctly reads an age from the user and converts it to an integer so that next_year = age + 1 can be calculated?
- A
int(input("Enter your age: ")) - B
float(input("Enter your age: ")) - C
str(input("Enter your age: ")) - D
bool(input("Enter your age: "))
What integer value does the Python expression 17 // 2 produce?
Which of the following can be used as an ordinary Python variable name?
- A
student_name - B
2students - C
class - D
total-cost
Which single Python operator produces the remainder after integer division?
What value does result refer to after this code runs?
result = "" or "guest"
- A
"" - B
"guest" - C
False - D
None
What string does word[1:4] produce when word = "Python"?
- A
"Pyt" - B
"yth" - C
"thon" - D
"Python"
Which expression evaluates as false when used in a Python Boolean context?
- A
0 - B
1 - C
" " - D
"Python"
Complete both blanks: A programmer wants to exchange the values of x and y without a temporary variable. The statements x, y = y, x work because Python evaluates the right-hand side before assigning the new values. A sequential approach such as x = y; y = x fails because . The comma-separated assignment used to exchange the values is called .
Complete both blanks: Given count = 3, the augmented assignment that increases count by one is . After that statement executes, the value of count is .
Explain the difference between score = 100 and score == 100 in Python. Include what each expression does and what kind of result the comparison produces.
Related study packs and tools
2 Digital Logic
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
03 — Python Programming Fundamentals
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
04 Conditionals and Boolean Logic
Learn how Boolean expressions, logical operators, and conditional structures let programs make reliable decisions, including how to handle boundaries, branch order, and testing.
6 Computer Memory
Learn how computer memory stores and addresses information, how RAM and ROM differ, and how caches and the memory hierarchy balance speed, capacity, and cost.
07 Trees and Binary Search Trees
A progressive guide to tree structure, binary-tree traversals, binary search tree operations, deletion, balancing, and the way tree height determines time and space costs.
12 — Foundations Capstone: Integrating Computer Science
A practical guide to integrating problem definition, data representation, modular programming, algorithms, complexity analysis, testing, correctness, and ethical evaluation into a responsible computer science capstone.
Interrupts
Reviews how interrupts support event handling and multitasking, and how Linux system calls use the RISC-V `ecall` instruction and register conventions.
OS Processes
This quiz covers process management, context switching and scheduling, multitasking, traps and interrupts, and RISC-V privilege transitions.
Systemcalls
A quiz on operating-system system calls, including privileged-operation requests, process creation and execution with fork, exec, and waitpid, and signal handling.