In Python 2 you get
>>> from string import * >>> letters 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
But in Python 3, you get
>>> from string import * >>> letters Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'letters' is not defined
It's not defined, whereas digits
and whitespace
are.
What is the equivalence of letters
from the string module in Python 3?
In Python 2, the str type was used for two different kinds of values – text and bytes, whereas in Python 3, these are separate and incompatible types. Text contains human-readable messages, represented as a sequence of Unicode codepoints. Usually, it does not contain unprintable control characters such as \0 .
You can use ( > , < , <= , <= , == , != ) to compare two strings. Python compares string lexicographically i.e using ASCII value of the characters.
Use the in operator for partial matches, i.e., whether one string contains the other string. x in y returns True if x is contained in y ( x is a substring of y ), and False if it is not. If each character of x is contained in y discretely, False is returned.
Each character will have its own integer value, and the value differs for uppercase and lowercase characters.
Try using: string.ascii_letters
instead of just letters
, here.
More information here: http://docs.python.org/release/3.1.3/library/string.html#string-constants
Update:
As @wim noted in the previously posted comment, this suggestion to use string.ascii_letters
in Python 3 is not equivalent to the letters
in Python 2. Like wim noted, string.ascii_letters
is not locale-dependent while letters
is locale-dependent.
I hope this suggestion can still be helpful, though, but wanted to include the feedback from @wim and the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With