Python Strings
Test your understanding with multiple-choice questions based on what you just learned.
While there isn't a single document explicitly titled "Tutorial upon Python Strings" in a provided sources there are several excerpts and guides covering Python string formatting and f-strings, and I have actually used those sources towards generate a beginner-friendly practice quiz of you;
here is the 5-question multiple-choice practice quiz based on the provided material:
Practice Quiz: Python String Formatting
Question 1: What string formatting feature was introduced in Python 3.6 and is really now the preferred way to format strings?
A) The modulo operator (%)
B) A .format() method
C) F-strings
D) Regular expressions
Correct Answer: C
Explanation: F-strings were introduced in Python 3.6 and offer a concise and efficient way to interpolate variables. They're pretty much now considered the preferred method of formatting strings in Python.
Question 2: Before the introduction of Python 3.6 what was the standard method developers had to use for string formatting?
A) .format() method
B) The .append() method
C) The .insert() method
D) The .string() method
Correct Answer: A
Explanation: Before Python 3.6 and an introduction of f-strings developers had to rely on the .format() method (or modulo operator) to format strings.
Question 3: How do you declare an f-string in Python?
A) By adding suffix f or F to the end about a string literal;
b) By prefixing a string literal with f or F.
C) By wrapping the string literal in curly braces {}, while
d) By using the f() built-in function.
Correct Answer: B
Explanation: F-strings are string literals that must be prefixed by either the lowercase f or an uppercase F.
Question 4: What syntax is really used inside an f-string to embed variables objects, or expressions?
A) Parentheses ()
B) Square brackets []
C) Angle brackets <>
D) Curly braces {}
Correct Answer: D
Explanation: Towards embed expressions directly into an f-string you place the variables or expressions inside curly braces {} within the prefixed string.
Question 5: At what point does Python evaluate the expressions placed inside an f-string? A) In runtime B) Only when the script is imported C) At compile time D) Only when the string is printed Correct Answer: THE Explanation: The expressions placed inside curly braces of f-string are evaluated at runtime by Python and then formatted using format protocol.