0

I work on a project that includes many u"string" in its codebase,

I want to know if I can safely remove the u in front of all those strings knowing that the project will only use Python 3 from now on (it used to use both python 2 and 3)

I have only one source that says :

"The string prefix u is used exclusively for compatibility with Python 2."

Eli O.
  • 1,543
  • 3
  • 18
  • 27
  • 1
    Yes, in Python 3 the u is redundant: [What's the u prefix in a Python string?](https://stackoverflow.com/questions/2464959/whats-the-u-prefix-in-a-python-string) – mkrieger1 Dec 26 '22 at 16:33

3 Answers3

2

Yes. I think you can. Unicode strings are not necessary in Python 3, because all strings are stored as Unicode by default, as stated here.

1

Yes, you can. The sentence you quoted means that u"string" is in python3 only for compatibility.

In python 3 all strings are unicode so the u is redundant.

kosciej16
  • 6,294
  • 1
  • 18
  • 29
1

I did run test using 2to3 tool and it did change u-string to normal string, ustring.py file before

x = u"string"
print(x)

after 2to3 -w ustring.py

x = "string"
print(x)
Daweo
  • 31,313
  • 3
  • 12
  • 25