How to generate a string of random letters in Python

A random string is a finite sequence of characters generated at random.

Solution for How to generate a string of random letters in Python : You can use random.choice() with string.ascii_letters to generate a string of random letters Call str.join(iterable) with str as “” and iterable as the generator expression choice(ascii_letters) for i in range(length_of_string). This expression uses random.choice(sequence) to pick a random character from the sequence string.ascii_letters a total of length_of_string times.

To also randomize the length of the string, call random.choice(sequence) on the result of calling range(start, stop) where start and stop-1 are the minimum and maximum bounds of the string length.

length_of_string = random.choice(range(5, 13))


how-to-generate-a-string-of-random-letters-in-python