Certified Associate in Python Programming (PCAP) — Question 47

You are going to read 16 bytes from a binary file into a bytearray called data. Which lines would you use? (Choose two.)

Answer options

Correct answer: A, D

Explanation

Option A correctly initializes a bytearray of size 16 and uses the readinto method to fill it with data from the binary file. Option D also works by reading 16 bytes directly into a new bytearray, which is valid. Options B and C are incorrect because they either attempt to create a bytearray incorrectly or misuse the readinto method.