Python Fundamentals · Practice set 6 of 8
Values, Text, and First Programs: 10 practice questions
10 free Python Fundamentals practice questions on Values, Text, and First Programs, with an explanation for every answer. Untimed. The full mock exam and the timed version are in the app.
-
Question 1 of 10
Which arithmetic operator always returns a floating-point result?
- A`/`
- B`//`
- C`%`
- D`**`
Show the answer
Regular division returns a float; floor division, remainder, and exponentiation perform different numeric operations.
Next → 1 / 10 -
Question 2 of 10
What happens when code tries to assign a new character to one indexed position of a string?
- APython raises `TypeError` because strings are immutable.
- BPython appends the character to the end of the string.
- CPython creates a new string and rebinds the original name automatically.
- DPython replaces the character because strings are mutable.
Show the answer
Indexed assignment cannot mutate a `str`; constructing a new value by combining slices and text is the supported contrast.
Next → 2 / 10 -
Question 3 of 10
Which list operation adds one new item at the end?
- ATake a slice of the entire list.
- BCall the list's `append()` method.
- CRead the list's final index.
- DAssign the list to another variable.
Show the answer
`append()` mutates a list by adding one item at its end; assignment and slicing have different object-sharing behavior.
Next → 3 / 10 -
Question 4 of 10
For `word = 'Python'`, what does the slice `word[2:5]` produce?
- A`'thon'`, because both slice boundaries are included.
- B`'yth'`, because slicing starts one position before index 2.
- C`'tho'`, because index 2 is included and index 5 is excluded.
- D`'ho'`, because both slice boundaries are excluded.
Show the answer
A slice spans from its included start edge up to, but not including, its end edge.
Next → 4 / 10 -
Question 5 of 10
After `rgba = rgb`, what happens if code appends an item through `rgba`?
- AOnly `rgba` changes because assignment makes a deep copy of the list.
- BOnly `rgb` changes because the original name owns all mutations.
- CThe appended item is also visible through `rgb` because both names refer to one list.
- DNeither list changes because list values are immutable.
Show the answer
Simple list assignment shares the existing object; a full slice is the neighboring operation that creates a new list.
Next → 5 / 10 -
Keep the ones you got wrong
In the app, every question you miss comes back exactly when you’re about to forget it.
-
Question 6 of 10
How does Python process `a, b = b, a + b` in the introductory Fibonacci program?
- AIt evaluates both right-hand expressions before performing either assignment.
- BIt assigns `a` first and then evaluates both right-hand expressions.
- CIt alternates evaluation and assignment from right to left.
- DIt assigns `b` first and then evaluates the expression for `a`.
Show the answer
Multiple assignment protects the old values by evaluating the complete right side first, from left to right, before names are updated.
Next → 6 / 10 -
Question 7 of 10
Why can Python display `0.1` even though the stored float is not exactly one tenth?
- APython stores the exact decimal value but rounds it to binary only during arithmetic.
- BPython changes the stored value to exact one tenth whenever it is printed.
- CPython stores every decimal fraction as a finite base-two fraction without approximation.
- DPython displays a rounded decimal form of the stored binary approximation.
Show the answer
Display formatting can choose a short representation while the machine value remains the nearest representable binary fraction.
Next → 7 / 10 -
Question 8 of 10
A program needs a string containing `C:\temp\new`, with each backslash preserved, and the value does not end in a backslash. Which literal best satisfies both constraints?
- AUse the ordinary string `'C:\temp\new'` unchanged.
- BUse `r'C:\temp\new\'` and remove the last character later.
- CUse adjacent literals `'C:' '\temp' '\new'` without raw prefixes.
- DUse the raw string `r'C:\temp\new'`.
Show the answer
A raw prefix preserves the backslash sequences here, and the requested value avoids the restriction on an odd final backslash.
Next → 8 / 10 -
Question 9 of 10
A countdown must repeat while a positive integer remains and print each value followed by a comma instead of a newline. Which design meets both requirements?
- AUse an empty list as the `while` condition and call `print(value, end=' ')` before decreasing it.
- BUse zero as the `while` condition and call `print(value)` before increasing it.
- CUse the integer as the `while` condition and write the expression at the prompt without `print()`.
- DUse the integer as the `while` condition and call `print(value, end=',')` before decreasing it.
Show the answer
A positive integer is true until it reaches zero, and the `end` keyword replaces `print()`'s normal newline with the requested comma.
Next → 9 / 10 -
Question 10 of 10
A report must show a short decimal result, while a test must tolerate the representation error in `0.1 + 0.1 + 0.1`. Which approach addresses both needs?
- APrint the full stored fraction and use exact equality because all displayed digits remove the error.
- BPre-round each `0.1` operand and use exact equality because the inputs then become exact.
- CFormat the report output and use exact equality because formatting changes the stored value.
- DFormat the report output to the desired digits and use `math.isclose()` for the comparison.
Show the answer
Formatting controls presentation without repairing binary representation, while `math.isclose()` supplies the documented approximate-comparison tool.
Next → 10 / 10 -
You’ve finished this set
That’s 10 questions on Values, Text, and First Programs. In the app the ones you miss come back exactly when you’re about to forget them.
The whole course, on your phone
Lessons you can read, audio you can listen to on the way to work, and practice that remembers what you got wrong.