Python2 和 Python3 要印出 a-z 的方法有哪些?
Python 印出 a-z 的方法
要印出 a-z 的方法,除了平常自己 a-z 寫出來、使用 ascii 的 97~123 來印,還可以使用 string 的物件。
Python2 使用 string
註:Python3 沒有辦法使用 string.lowercase
import string
for w in string.lowercase[:]:
print w
for w in string.lowercase[:8]:
print w
for w in string.lowercase[3:8]:
print w
Python2 / Python3
使用 ascii
使用 ascii
使用 string
import string
print(string.ascii_lowercase)
print(list(string.ascii_lowercase))
for w in list(string.ascii_lowercase):
print(w)
for w in list(string.ascii_lowercase)[3:8]:
print(w)
相關
Python 的 List 如果有中文的話, 會印出 \xe4\xb8... 等等的編碼, 要如何印…
在「Programming」中
一個純文字檔裡面, 每行一個字串, 要將重複的字串移除, 要怎麼做比較快? 原始檔案: data.t…
在「My_Note-Unix」中
Python 於 CLI 要將命令列後面所有參數(argv)的值,全部變成一個字串,要怎麼做呢? 註…
在「Programming」中