Basics of Python – String Constants

Python string constants: In this Page, We are Providing Basics of Python – String Constants. Students can visit for more Detail and Explanation of Python Handwritten Notes Pdf.

Basics of Python – String Constants

String constants

Some constants defined in the string module are as follows:

string. ascii_lowercase
It returns a string containing the lowercase letters ‘ abcdefghijklmnopqrstuvwxyz ‘.

>>> import string
>>> string . ascii_lowercase
' abcdefghijklmnopqrstuvwxyz '

string. ascii_uppercase
It returns a string containing uppercase letters ‘ ABCDEFGHIJKLMNOPQRSTUVWXYZ ‘.

>>> string . ascii_uppercase 
' ABCDEFGHIJKLMNOPQRSTUVWXYZ '

string. ascii_letters
It returns a string containing the concatenation of the ascii_lowercase and ascii_uppercase constants.

>>> string . ascii_letters
' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '

string. digits
It returns the string containing the digits ‘ 0123456789 ‘.

>>> string.digits 
' 0123456789 '

String.hex digits
It returns the string containing hexadecimal characters ‘ 0123456789abcdef ABCDEF ‘.

>>> string.hexdigits 
' 0123456789abcdef ABCDEF ’

string.octdigits
It returns the string containing octal characters ‘ 01234567 ‘.

>>> string.octdigits 
' 01234567 '

string. punctuation
It returns the string of ASCII characters which are considered punctuation characters.

>>> string.punctuation
‘ ! ” # $ % & \ ‘ ( ) * + , – . / : ; <=> ? @ [ \\ ] ∧ _ ‘ { | } ∼ ‘

string. whitespace
It returns the string containing all characters that are considered whitespace like space, tab, vertical tab, etc.

>>> string.whitespace
‘ \ t \ n \ x0b \ x0c \ r ‘

string. printable
It returns the string of characters that are considered printable. This is a combination of digits, letters, punctuation, and whitespace.

>>> string . printable
' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ! " # $ % & \ ' ( ) * + , - . / : ; <=> ? 0 [ \\ ]∧ _ ' { I \ t \ n \ r \ x0b \ x0c  '

Python String Programs