The following code:
x = '\'' print(len(x)) prints:
- 3
- 1
- 20
- 2
Explanation: Let’s analyze this code snippet:
- A string variable named x is defined.
- The first and last single quotes delimit the contents within the variable, and are not part of the content.
- The backslash is the escape character, which also does not count as part of the content.
- The single quote after the backslash is the only character that is part of the variable contents.
- Using the print function, the character length of the variable is shown in the console, and the answer is 1.
More Questions: Python Essentials 2 – Module 2 Test
Please login or Register to submit your answer