bytearray() — Python Technical Interview Questions & Answers
bytearray()
bytearray()
- bytearray() is built into Python. You do not import it. Freshers only need one honest call and the printed result — not a long definition.
- bytearray() — output: bytearray(b'Ji'). Mutable bytes.
- Wrong type often raises TypeError. Empty values matter for bool/all/any. Don’t mix bytearray up with a similar name (sorted vs sort, int vs float).
Technical Interview Tip: Call bytearray() once and say what prints.
Code Examples for bytearray()
Example
# bytearray()
b = bytearray(b"Hi")
b[0] = 74
print(b)
bytearray() — output: bytearray(b'Ji'). Mutable bytes.
How to Explain bytearray() to an Interviewer
Explain bytearray() as if you are teaching a junior — definition, then one tiny script.
bytearray() is built-in — no import. One call + exact output.
What does the example print, and why?
bytearray() — output: bytearray(b'Ji')
What mistake do freshers make with bytearray()?
Wrong type → TypeError.