我可以簡單地++一個字符?這樣做的有效方式是什麼?我想通過具有www.website.com/term/#,www.website.com/term/a,www.website.com/term/b,www.website.com/term/c,www的url進行迭代.website.com /學期/ d ... www.website.com/term/z格式如何在Python中遍歷字母表?
45
A
回答
74
您可以使用string.ascii_lowercase
這是一個簡單的小寫字母便利串,
>>> from string import ascii_lowercase
>>> for c in ascii_lowercase:
... # append to your url
15
除了string.ascii_lowercase
你還應該看看內置的ord
和chr
。 ord('a')
會給你'a'
和chr(ord('a'))
的ascii值會給你回字符串'a'
。
使用這些可以通過字符代碼進行遞增和遞減,並且可以輕鬆地來回轉換。 ASCII table總是一個不錯的書籤。
相關問題
- 1. xsl遍歷字母列表
- 2. 如何遍歷Visual Basic中的字母表?
- 3. 如何遍歷在Python
- 4. 如何遍歷在Python
- 5. 遍歷python中的字符串列表
- 6. Python遍歷字典
- 7. 遍歷Python列表只給每個字母
- 8. 遍歷列表(Python)
- 9. 遍歷在Python
- 10. 遍歷在Python
- 11. 遍歷在Python
- 12. 遍歷在Python
- 13. 遍歷在Python
- 14. 如何在Python中遍歷Rtree 0.6.0
- 15. 如何遍歷字符串數組Python
- 16. Python CSV如何遍歷列表
- 17. 在Python中循環遍歷數字
- 18. 在Python中遍歷XML
- 19. 在Python中預先遍歷
- 20. Python金字塔遍歷
- 21. 如何在python中打印字母表?
- 22. 的Python 3:嘗試基於功能遍歷字母表中的行i
- 23. 如何在Lua中遍歷表?
- 24. 的Python:遍歷列表
- 25. Python循環遍歷列表
- 26. 如何遍歷字節數組列表...?
- 27. 如何遍歷字典列表?
- 28. 如何遍歷字典列表?
- 29. 如何在Python中以隨機順序遍歷字典?
- 30. 如何遍歷python中的optparse.OptionGroup值
有308,915,776(26^6)種方法可以用任何字母組合六個字母的長字符串 - 只是讓您意識到如果您的工作進展超出了一個字母。 – Patashu