使用Python3时,做一些像
这样简单的事情x=input("Enter your name: ")
print (x)
并试图运行它,用户必须输入他们的名字作为" Steve"而不只是史蒂夫。
有没有办法输入报价?
答案 0 :(得分:11)
我觉得你错了。在Python 3中,不需要引号:
localhost-2:~ $ python3.3
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 01:25:11)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = input("Enter your name:")
Enter your name:Steve
>>> x
'Steve'
你会在Python 2的旧时代,因为input
基本上eval
是你提供的:
>>> x = input("Enter your name:")
Enter your name:Steve
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'Steve' is not defined
>>> x = input("Enter your name:")
Enter your name:"Steve"
>>> x
'Steve'
所以你改用raw_input
:
>>> x = raw_input("Enter your name:")
Enter your name:Steve
>>> x
'Steve'
但是在Python 3中,input
是raw_input
过去的原因,因此不需要引号。