Difference between bytes and bytearray in Python

bytes

  • It returns the "bytes" Object. 
  • It is immutable. (cannot be modified once declared).
  • It is the sequence of a small integer whose range is from 0<=x<256.
bytes([source [, encoding [, errors]]])

 bytearray

  • This method returns the bytearray object (i.e. array of given bytes).
  • It is a mutable(can be modified) sequence of bytes.
  • It is the sequence of integers in the range 0 <= x < 256.
bytearray([source[,encoding [,errors]]])
Tags