Python What Does ‘u', 'r', 'b' Mean in Front of a String

1. ‘u’ means Unicode

The ‘u’ in front of a string means the string is a Unicode string.

1
2
hello_rus = u"Привет, мир"
hello_rus

In Python 2.x, a Unicode string is marked with ‘u’.

However, in Python 3 all strings are Unicode strings by default. Thus you will never see ‘u’ in front of a Unicode string in Python 3.

2. ‘r’ means raw strings

1
2
3
print('C:\some\name')  	# here \n means newline!

print(r'C:\some\name') # note the r before the quote

3. ‘b’ means bytes

The b”” notation is used to specify a bytes string in Python.

1
my_string = b'The string'

Python What Does ‘u', 'r', 'b' Mean in Front of a String
https://www.hardyhu.cn/2022/02/25/Python-What-Does-‘u-r-b-Mean-in-Front-of-a-String/
Author
John Doe
Posted on
February 25, 2022
Licensed under