Python string ascii_lowercase

In this article, We will discuss the ascii_lowercase constant of the string module in Python with examples.

Introduction:- The ascii lowercase is a predefined string and generally is used as a string constant. It returns lowercase letters from a to z as a string. The returned string from this constant is not locale-dependent and will not change.

Syntax: Syntax of ASCII lowercase is-

Imported Module: We need to import the Python string library function in our program before using string ascii lowercase.

Parameter: string ascii lowercase does not take any parameter as it is not a function or method.

Example 1:

#importing required module-->string 
import string
#storing the result in a variable returned_value
#printing the returned value



Applications: The String ascii lowercase has various applications like generating a strong random password of a given size, checking whether a string has all ascii lowercase characters or not.

Example 2: below is the given Python code to check whether a string has all ascii_lowercase letters or not:

#importing required module-->string 
import string
#function for checking whether a string is in lowercase letters or not 
def func(name):
    for i in name:
        #If a string does not have all lowercase characters,returns False
        #Otherwise returns True
        if i not in string.ascii_lowercase:
            return False
            return True
#Code for testing        

Output :


Example 3: Code to create a strong random password that fulfills Linode requirements.
Linode API consists of at least two of these four character classes-
uppercase letters, lowercase letters, numbers, punctuation.

def strongpass():
    import random
    import string
    lowercase = ''.join(random.choice(string.ascii_lowercase) for i in range(5))
    uppercase = ''.join(random.choice(string.ascii_uppercase) for i in range(5))
    numeric = ''.join(random.choice(string.digits) for i in range(5))
    password = lowercase + uppercase + numeric
    return ''.join(random.sample(password, len(password)))

Output :


I hope, this article will help you to understand the concept and examples of string ascii lowercase.

Also, read: Padding A String in Python programming

Leave a Reply

Your email address will not be published. Required fields are marked *