Is it possible to make a letter range in python?

前端 未结 8 1642
误落风尘
误落风尘 2021-01-02 17:23

Is there a way to do a letter range in python like this:

for x in range(a,h,)
8条回答
  •  猫巷女王i
    2021-01-02 18:03

    Something like:

    [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)
    

提交回复
热议问题