In Python3, ascii_letters is a pre-initialized string used as string constant.
ascii_letters is basically concatenation of ascii_lowercase and ascii_uppercase string constants. Also, the value generated is not locale-dependent, hence, doesn’t change.
Note : Make sure to import string library function inorder to use ascii_letters.
Doesn't take any parameter, since it's not a function.
Return all ASCII letters (both lower and upper case)
Code #1 :
Code #2 :
Given code checks if the string input has only ASCII characters or not.
GeeksForGeeks --> True Geeks for Geeks --> False Geeks_for_geeks --> False
The string constant ascii_letters can be used in many practical applications.
Let’s see a code explaining how to use ascii_letters to generate strong random passwords of given size.
Code #1 :
Note : Above given code will print random (different) password everytime, for the size provided.
Code #2 :
Say if you want to generate random password, but from the set of given string. Let’s see how can we do this using ascii_letters :
- String slicing in Python to check if a string can become empty by recursive deletion
- Python | Check if given string can be formed by concatenating string elements of list
- Python | Check if string ends with any string in given list
- String slicing in Python to rotate a string
- Python | Check if a given string is binary string or not
- Python String | max()
- Python String | min()
- Python | Add one string to another
- Python String
- String rindex() in python
- Python String | isidentifier()
- Python | String startswith()
- Python String | rpartition()
- Python string | digits
- Python string | ascii_lowercase
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.