是否可以在python中创建一个字母范围? [英] Is it possible to make a letter range in python?
本文介绍了是否可以在python中创建一个字母范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法像这样在python中做一个字母范围:
Is there a way to do a letter range in python like this:
for x in range(a,h,)
推荐答案
类似:
[chr(i) for i in range(ord('a'),ord('h'))]
将给出一个要迭代的字母字符列表,然后您可以在循环中使用这些字符
Will give a list of alphabetical characters to iterate through, which you can then use in a loop
for x in [chr(i) for i in range(ord('a'),ord('h'))]:
print(x)
或者这会做同样的事情:
or this will do the same:
for x in map(chr, range(*map(ord,['a', 'h']))):
print(x)
这篇关于是否可以在python中创建一个字母范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文