How do I iterate through the alphabet?

后端 未结 2 1971
被撕碎了的回忆
被撕碎了的回忆 2021-02-03 16:18

In Python, could I simply ++ a char? What is an efficient way of doing this?

I want to iterate through URLs that have the www.website.com/term/#, www.website.com/term/a,

2条回答
  •  天命终不由人
    2021-02-03 17:21

    In addition to string.ascii_lowercase you should also take a look at the ord and chr built-ins. ord('a') will give you the ascii value for 'a' and chr(ord('a')) will give you back the string 'a'.

    Using these you can increment and decrement through character codes and convert back and forth easily enough. ASCII table is always a good bookmark to have too.

提交回复
热议问题