Exam GPYC All QuestionsBrowse all questions from this exam
Question 26

Review the following code:

What is the output?

    Correct Answer: B

    The code uses the struct module to unpack a binary string. The given string '\x01\x00' represents a 2-byte value. The '<H' format string specifies little-endian order with an unsigned short (2 bytes). In little-endian byte order, the least significant byte comes first. Therefore, '\x01\x00' is read as 0x0001, which is equal to the integer value 1. The unpack function returns a tuple with one element, which is (1,).

Discussion
howefo8913Option: B

>>> a = "\x01\x00" >>> struct.unpack("<H",a) (1,) >>>

a29dc2cOption: B

that answer is B