You can download this code by clicking the button below.
This code is now available for download.
Generate a random string of a specified length using the string module.
Technology Stack : String handling
Code Type : Function
Code Difficulty :
import random
def generate_random_string(length=10):
"""
Generate a random string of a given length using the string module.
"""
letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
result_str = ''.join(random.choice(letters) for i in range(length))
return result_str