DEV Community

Cover image for The Most Used Python string Module Constants
Aya Bouchiha
Aya Bouchiha

Posted on

2 1

The Most Used Python string Module Constants

Importing string module

import string
Enter fullscreen mode Exit fullscreen mode

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'>
Enter fullscreen mode Exit fullscreen mode

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)) 
Enter fullscreen mode Exit fullscreen mode

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)) 
Enter fullscreen mode Exit fullscreen mode

ascii_lowercase

  • ascii_lowercase: returns all lowercase alphabet letters.
import string

# abcdefghijklmnopqrstuvwxyz
print(string.ascii_lowercase) 

# 26
print(len(string.ascii_lowercase)) 
Enter fullscreen mode Exit fullscreen mode

ponctuation

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

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

# 32
print(len(string.punctuation)) 

# <class 'str'>
print(type(string.punctuation))
Enter fullscreen mode Exit fullscreen mode

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:

email: developer.aya.b@gmail.com

telegram: Aya Bouchiha

Hope you enjoyed reading this post :)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay