10
QuizMultiple Choice

Readable Code — Unit test

Question 10 • VA-Information Technology Fundamentals B

Which can be used to decode a Unicode character encoding into text?

Answer
A
stringVariable=unicodeString.decode(decoding= “utf-8”, errors= “strict”)
B
stringVariable=unicodeString.encode(encoding= “utf-8”, errors= “strict”)
C
stringVariable=unicodeString.decode(encoding= “utf-8”, errors= “strict”)
D
stringVariable=unicodeString.encode(decoding= “utf-8”, errors= “strict”)

Explanation

Decoding converts encoded bytes into text, and Python uses the decode() method with the encoding named in the encoding parameter. So unicodeString.decode(encoding="utf-8", errors="strict") is the correct form. The encode() method converts text into bytes, while the decoding parameter in choice A is not the correct parameter name.

AI-written and checked against the verified answer.

Previous
Next