2012-03-05 100 views
14

在Python 2你Python 2中字母Python 3的等價性是什麼?

>>> from string import * 
>>> letters 
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' 

但是在Python 3,你

>>> from string import * 
>>> letters 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
NameError: name 'letters' is not defined 

它沒有定義,而digitswhitespace是。

什麼是letters與Python 3中字符串模塊的等價關係?

回答

24

嘗試使用:string.ascii_letters而不是僅僅letters,在這裏。

更多的信息在這裏:http://docs.python.org/release/3.1.3/library/string.html#string-constants

+1

thanx它的工作! – CosmicRabbitMediaInc 2012-03-05 04:07:39

+0

@CosmicRabbitMediaInc:請注意,只有在您甚至遇到英文文本時纔會有效。 – 2012-03-05 05:53:11

+0

對我來說,我不得不刪除'string.'部分。簡單地使用'ascii_letters'在我的python 3.6上工作 – 2017-04-21 13:36:48

相關問題