How are integers converted to bytes character sequences, such as 1-> bounded 1'?

such as the title.
I just want to use str to convert to a string, and then encode to convert to bytes:

>>> str(1).encode("utf-8")
b"1"

is there an easier way?

Mar.06,2021

looks like you're using python3, right?
you can use bytes (1) directly in python2, while in python3 you can also use bytes (str (1), 'utf8') . Manually funny:)

Menu