# How To Convert Numbers To Letters In Python

To convert numbers to letters in Python, you can use the chr() or the ord() functions. Let’s get started to learn more about it.

## Convert Numbers To Letters In Python

### Convert a number to a letter with the chr() function

You can use the chr() function to convert a number to a letter in Python. This function is used to convert an integer number to a letter based on the ASCII value of the letter.

Look at the example below.

def number_to_letter(number=0):
# Convert a number to a letter with the chr() function.
letter = chr(number)
return letter

# The number to be converted.
number = 68
print('{} to letter: {}'.format(number, number_to_letter(number)))

# Try with another number.
number = 105
print('{} to letter: {}'.format(number, number_to_letter(number)))

Output

68 to letter: D
105 to letter: i

### Convert a number to a letter with the ord() function

Besides the chr() function, you can use the ord() function to convert a number to a letter in Python. First, we need to create a list of letters. Then, we iterate it until we find the ASCII value of the letter in the list is equal to the specified number.

Look at the example below.

def number_to_letter(number=0):
# The list of letters.
letter_list = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

# Convert a number to a letter with the ord() function.
for letter in letter_list:
if ord(letter) == number:
return letter

# The number to be converted.
number = 68
print('{} to letter: {}'.format(number, number_to_letter(number)))

# Try with another number.
number = 105
print('{} to letter: {}'.format(number, number_to_letter(number)))

Output

68 to letter: D
105 to letter: i

### Convert numbers to letters

To convert numbers to letters in Python, you can apply the chr() or ord() functions. In this example, we will apply the chr() for simplicity.

Look at the example below.

def numbers_to_letters(numbers=list()):
# Convert numbers to letters with the chr() function and the list comprehension.
letter_list = [chr(number) for number in numbers]
return letter_list

# The numbers to be converted.
number_list = [67, 68, 105, 111, 70, 86, 116, 105]
print('Numbers: {}'.format(number_list))

# Convert numbers to letters.
letter_list = numbers_to_letters(number_list)
print('Letters: {}'.format(letter_list))

Output

Numbers: [67, 68, 105, 111, 70, 86, 116, 105]
Letters: ['C', 'D', 'i', 'o', 'F', 'V', 't', 'i']

Besides, you can learn how to generate random letters here.

## Summary

We have shown you how to convert numbers to letters in Python in 2 ways. In our opinion, you should use the chr() function because you can achieve the goal directly with one statement, unlike the ord() function. We hope this tutorial is helpful to you. Thanks!