Friday , September 20 2024

What is the expected result of the following code? b = bytearray(3) print(b)

Questions BankCategory: Python Essentials 2What is the expected result of the following code? b = bytearray(3) print(b)
What is the expected result of the following code?

b = bytearray(3)
print(b)
  • bytearray(b’3′)
  • bytearray(b’\x00\x00\x00′)
  • bytearray(0, 0, 0)
  • 3

Explanation: Remember that the bytearray() function creates an array of bytes. Since 3 is specified as an argument, the b bytearray will consist of 3 empty bytes. Then, the print function outputs them to console: bytearray(b’\x00\x00\x00′).

More Questions: Python Essentials 2 – Module 4 Test