C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Info: With ascii, a built-in, we escape Unicode characters into ASCII characters.
Python program that uses ascii built-in
# This string contains an umlaut.
value = "Düsseldorf"
print(value)
# Display letter with escaped umlaut.
print(ascii(value))
Output
Düsseldorf
'D\xfcsseldorf'
Tip: We import the string module and access these constants on it. This is an easy to way to access the constants.
Python program that uses ascii_letters constant
import string
# The letters constant is equal to lowercase + uppercase.
print(string.ascii_letters)
print(string.ascii_lowercase)
print(string.ascii_uppercase)
Output
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Python program that uses string.digits
import string
# Loop over digits using string.digits constant.
for digit in string.digits:
print(digit)
Output
0
1
2
3
4
5
6
7
8
9