0
How can i make a range of alphabetical letters in python by range function
Like range(a,z) won't work , i want a similar and valid code like that . Anyone having any tips?
6 ответов
+ 3
Very simple, you can create with just one line:
Two simple ways:
Alphabetlist = [chr(i) for i in range(97, 123)]
Or if you would rather print them directly without saving them in a list:
print(*(chr(i) for i in range(97, 123)))
+ 4
Try using the chr - function. It turns an int into a letter.
You can look that up in the ASCII table.
Hint: chr(97) will give you 'a'
+ 2
That IS very easy!
Try it out:
print(chr(97))
+ 1
look up the string module too, it has a method to get alphabetical character i .e lowercase, upper or both as a string so you can sent it to - for example- the list constructor.
By 'range' i assume you mean ' a collection' rather than python range function.
import string
mystring1 = list(string.ascii_lowercase)
print(mystring1)
# or... depending on wht you want
mystring2 = string.ascii_lowercase
print(mystring2)
+ 1
Yo thanks a tonne fellas.
It was really helpful!!👌😊