Four ways to print 26 letters in python
1. Use the ascii_letters method directly
code show as below:
print(string.ascii_letters[:26])
2. Use the ord method of the string to convert it into an ascii value
code show as below:
var='a'
lst=[chr(ord(var)+i) for i in range(26)]
print(''.join(lst))
3. Use the map function
code show as below:
print(list(map(chr,range(ord('a'),ord('z')+1))))
map function usage:
map(function, iterable, ...)
- The first parameter function calls the function function with each element in the parameter sequence and returns a new list containing the return value of each function function.