String constants in python

Allwin Raju
Nerd For Tech
Published in
3 min readMay 30, 2021

The string module has some of the built-in constant variables. We can use this instead of declaring the constants again in our code. Some of the string constants that will be discussed here are,

  1. ascii_letters
  2. ascii_lowercase
  3. ascii_uppercase
  4. octdigits
  5. punctuation
  6. whitespace

Let us look at these constants one by one with a code snippet printing each of these string constants.

1. ascii_letters

The ascii_letters constant is the concatenation of both lowercase and uppercase alphabets as a string. Let us import the string module and print this constant.

2. ascii_lowercase

The ascii_lowercase constant consists of all the lower case alphabets together as a string. Let us import the string module and print this constant.

3. ascii_uppercase

The ascii_uppercase constant consists of all the upper case alphabets together as a string. Let us import the string module and print this constant.

4. octdigits

The octdigits constant will print all the digits that are allowed in an octal number which is numbers from 0 to 7. Let us import the string module and print this constant.

5. punctuation

The punctuation constant has a string of punctuations. Let us import the string module and print this constant.

6. whitespace

A string containing all characters that are considered whitespace. On most systems, this includes the characters space, tab, linefeed, return, formfeed, and vertical tab.

Conclusion

If you want to remove punctuations from your code or check if all alphabets exist in your code or something like that we can use these string constants.

Happy coding!

--

--