在Python 2中你得到了
>>> from string import *
>>> letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
Run Code Online (Sandbox Code Playgroud)
但是在Python 3中,你得到了
>>> from string import *
>>> letters
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'letters' is not defined
Run Code Online (Sandbox Code Playgroud)
它没有定义,而是digits和whitespace.
lettersPython 3中字符串模块的等价性是什么?
我想A, b, c, d...使用 range()打印Python中包含的英文字母,但出现 TypeError。有没有一种方法可以做到这一点而不必手动定义英文字母列表?
>>> for letter in range('a', 'z'):
... print(letters)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object cannot be interpreted as an integer
>>>
Run Code Online (Sandbox Code Playgroud)