Question 14
Back to Exercise
What is the output of the following Python program?
import os, tempfile
os.chdir(tempfile.mkdtemp())
s = "café ₹"
with open("u.txt", "w", encoding="utf-8") as f:
f.write(s)
print(len(s), len(s.encode("utf-8")), os.path.getsize("u.txt"))
- A 6 6 6
- B 9 9 9
- C 6 9 6
- D 6 9 9 Correct
Correct Answer: Option D
6 characters. In UTF-8, é takes 2 bytes and ₹ takes 3: 3 + 2 + 1 + 3 = 9 bytes, which is also the file size.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!