Which statement best describes a Python variable?
2 Variables, Types, and Expressions Online Quiz Questions
Use this free practice quiz with 20 questions to review 2 Variables, Types, and Expressions, test your knowledge, and prepare for your next test or exam.
True or false: In Python, a variable name has a permanently declared type that cannot change during program execution.
- A
True
- B
False
To convert the string "42" into the integer 42, use the function.
What happens when Python executes area = width * height?
- A
The expression on the right is evaluated, then its result is bound to the name on the left.
- B
The name on the left is compared with the expression on the right.
- C
The expression on the left is evaluated, then its result is bound to the name on the right.
- D
Both sides must already contain equal values.
True or false: After numbers = [1, 2, 3] and copy_of_numbers = numbers[:], appending 4 to copy_of_numbers also appends 4 to numbers.
- A
True
- B
False
What integer does int(3.9) produce?
Given whole = 7 // 3 and remainder = 7 % 3, which result is correct?
- A
wholeis2andremainderis1. - B
wholeis2.3333333333333335andremainderis0. - C
wholeis3andremainderis1. - D
Both variables are
1.
A list is , while a string is .
Select all the Python types below that are commonly mutable.
- A
list - B
int - C
dict - D
str - E
tuple - F
set
A program reads quantity as a whole-number item count and unit_price as a price that may include cents. Which choices correctly prepare these values for total = quantity * unit_price? Select all that apply.
- A
Use
str()for both inputs. - B
Use
int()forquantity. - C
Use
float()forunit_price. - D
Use
bool()forunit_price.
Consider this code:
numbers = [1, 2, 3]
other_numbers = numbers
other_numbers.append(4)
Explain why printing numbers produces the changed list, and describe one way to create an independent shallow copy instead.
What text is printed by this code?
name = "Ada"
year = 1843
print(f"{name} was born in {year}.")
- A
{name} was born in {year}. - B
Ada was born in 1843. - C
name was born in year. - D
Ada was born in {1843}.
Which statement best describes how Python evaluates total = price * quantity?
- A
The name on the left is compared with the expression on the right.
- B
The expression on the right is evaluated before its result is bound to the name on the left.
- C
The name on the left is converted to the type of the expression on the right before evaluation.
- D
Both sides are evaluated as Boolean conditions.
What value does whole = int(3.9) assign to whole?
- A
3 - B
4 - C
3.9 - D
A
ValueErroris raised.
True or false: In Python, an empty list evaluates as false in a Boolean context.
- A
True
- B
False
Which statement creates a separate shallow copy of the list numbers so that later appending to the copy does not change the original list?
- A
copy_of_numbers = numbers[:] - B
copy_of_numbers = numbers - C
copy_of_numbers = numbers.append(4) - D
copy_of_numbers = str(numbers)
What Python type does input() return before the program applies a conversion such as int() or float()?
What integer value does int(-3.9) produce?
A developer is inspecting a string variable named message and wants a representation that is especially useful for debugging, including details such as quotation marks or escape characters when relevant. Which expression should the developer use?
- A
str(message)
- B
repr(message)
- C
format(message)
- D
type(message)
The variable value may refer to any object or to the absence-of-a-value marker. Enter the exact Python expression recommended for checking whether value refers to that marker.
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.