Generating Random Alphabet in Python

There are two ways to generate a random alphabet in python.

The first method uses string and random modules.

import string
import random
randomAlphabet = random.choice(string.ascii_letters)
print(randomAlphabet)
Python
The second method uses random module only.
import random
randomCharacter = chr(random.randint(ord("a"), ord("z")))
print(randomCharacter)
Python

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

Making GUI Calculator in Tkinter Python

Unlocking Web Design: A Guide to Mastering CSS Layout Modes