What does the r prefix do in r"C:\new"?
Without r, "\n" would become a newline. Raw strings are standard for regex patterns and Windows paths.
Strings · Exercise 1 of 4
Fifteen multiple-choice questions on Python strings: immutability, indexing and slicing, find vs index, split and join, character tests, comparison and formatting. Pick an option to check your answer instantly.
What does the r prefix do in r"C:\new"?
Without r, "\n" would become a newline. Raw strings are standard for regex patterns and Windows paths.
What is "aaaa".count("aa")?
count() finds non-overlapping occurrences: positions 0–1 and 2–3. Overlapping matches (3) need a loop or a regex lookahead.
What does chr(ord("a") + 1) return?
ord("a") is 97, 97 + 1 = 98, and chr(98) is "b".
What is special about a triple-quoted string such as """…"""?
It is an ordinary str that may contain newlines. Used as the first statement of a function it becomes a docstring.
What does f"{3.14159:.2f}" produce?
.2f formats the number with exactly two digits after the decimal point, rounding as needed.
Timed online tests with instant scores and explanations.