The Most Used Python string Module Constants

Importing string module

import string

the most used python string module constants

digits

  • digits: returns numbers from 0 to 9 as a string.
import string

print(string.digits) # 0123456789
print(type(string.digits)) # <class 'str'>

ascii_letters

  • ascii_letters: lets you get all lowercase and uppercase alphabet letters.
import string

# abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
print(string.ascii_letters) 

# 52 (26 * 2)
print(len(string.ascii_letters))

ascii_uppercase

  • ascii_uppercase: helps you to get all uppercase alphabet letters.
import string

# ABCDEFGHIJKLMNOPQRSTUVWXYZ
print(string.ascii_uppercase) 

# 26
print(len(string.ascii_uppercase))

ascii_lowercase

  • ascii_lowercase: returns all lowercase alphabet letters.
import string

# abcdefghijklmnopqrstuvwxyz
print(string.ascii_lowercase) 

# 26
print(len(string.ascii_lowercase))

ponctuation

  • punctuation: lets you get all punctuation symbols.
import string

# !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
print(string.punctuation) 

# 32
print(len(string.punctuation)) 

# <class 'str'>
print(type(string.punctuation))

Summary

  • digits: returns numbers from 0 to 9 as a string.
  • ascii_letters: returns all lowercase and uppercase alphabet letters.
  • ascii_uppercase: returns all uppercase alphabet letters.
  • ascii_lowercase: returns all lowercase alphabet letters.
  • ponctuaion: returns all punctuation symbols.

Suggested Posts

To Contact Me:

telegram: Aya Bouchiha

Hope you enjoyed reading this post :)

13