Why do you put "b" in front of the string?

Asked 2 years ago, Updated 2 years ago, 143 views

my_string = b'The string'

They put b in front of the string like this, and I wonder what it means, what influence it has, and when it is used.

string python binary unicode

2022-09-22 16:44

1 Answers

If you add b to the string in Python 3, it becomes a byte type. If you run it in REPL, it's as follows.

>>> a = b'abc'
>>> type(a)
<class 'bytes'>
>>> b = 'abc'
>>> type(b)
<class 'str'>


2022-09-22 16:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.