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?

5th Oct 2019, 11:57 AM
Kirtxn
Kirtxn - avatar
6 Réponses
+ 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)))
5th Oct 2019, 12:44 PM
William M
William M - avatar
+ 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'
5th Oct 2019, 12:09 PM
HonFu
HonFu - avatar
+ 2
That IS very easy! Try it out: print(chr(97))
5th Oct 2019, 12:12 PM
HonFu
HonFu - avatar
5th Oct 2019, 1:08 PM
Anton Böhler
Anton Böhler - avatar
+ 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)
5th Oct 2019, 1:03 PM
rodwynnejones
rodwynnejones - avatar
+ 1
Yo thanks a tonne fellas. It was really helpful!!👌😊
5th Oct 2019, 2:48 PM
Kirtxn
Kirtxn - avatar