相关疑难解决方法(0)

Python 2中Python 3中字母的等价性是什么?

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

它没有定义,而是digitswhitespace.

lettersPython 3中字符串模块的等价性是什么?

python python-3.x

24
推荐指数
1
解决办法
1万
查看次数

5
推荐指数
2
解决办法
1万
查看次数

打印范围内的英文字母

我想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)

python

2
推荐指数
1
解决办法
51
查看次数

标签 统计

python ×3

python-3.x ×2