Friday , September 20 2024

The following code: print(chr(ord(‘z’) ‑ 2)) prints:

Questions BankCategory: Python Essentials 2The following code: print(chr(ord(‘z’) ‑ 2)) prints:
The following code:

print(chr(ord('z') ‑ 2))
 

prints:
  • a
  • y
  • z
  • x

Explanation: The ord() function in Python returns the Unicode code of the given character. A lower-case z returns a 122. Then 2 is subtracted from 122, which results in 120. Finally, the 120 value is converted to its Unicode character x using the chr() function. So, x is printed in the console.

More Questions: Python Essentials 2 – Module 2 Test