Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is x = b'ABC' equivalent to x='ABC'.encode("ascii") in python3.5?

Is x = b'ABC' equivalent to x='ABC'.encode("ascii") in Python 3.5? Are there any differences between these two methods.

like image 845
Keith Avatar asked May 10 '26 08:05

Keith


1 Answers

They produce the same result:

>>> 'ABC'.encode("ascii")
b'ABC'
>>> b'ABC'
b'ABC'

However encode() will call the encoder at runtime, instead of at compile time.

like image 191
Stephen Rauch Avatar answered May 11 '26 20:05

Stephen Rauch