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
- Python How to Get First N Characters in a String
- Python How to Get Last N Characters in a String
- Python How to Iterate Over The Characters in String
- Check The First or Last Character of a String in Python
- Python How to Convert a List to String
- Python How to Convert Datetime Object to String Using Datetime Strftime
- Python How to Convert integer to String 5 Ways
- Python How to Sort a List of Strings List Sort Tutorial Examples
- Python Capitalize The First Letter of Each Word in a String
- Remove Last N Characters From String in Python
- Python How to Access Characters in String by index
- Python How to Replace Single or Multiple Characters in a String
- Python Replace Multiple Characters in a String
- Python Convert String Float
- Python Replace a Character in a String
- Python How to Pad Strings With Zero Space or Some Other Character
- Python How to Remove Characters From a String by index
- Check If Type of a Variable Is String in Python 3 Ways
- Python Check If String Is Empty or Blank or Contain Spaces only