输入和输出
今天在第一次学习python的输入和输出的时候遇到一个命令错误问题:
name = input('please enter your name: ')
print('hello,', name)
[root@cen68 ~]# python cs.py
please enter your name: ss
Traceback (most recent call last):
File "cs.py", line 1, in <module>
name = input('please enter your name: ')
File "<string>", line 1, in <module>
NameError: name 'ss' is not defined
执行命令的时候遇到NameError问题,经过查询才知道,输入字符串的命令,在2.6版本下是raw_input,我的python默认版本是2.6.而在版本3里面input就是raw_input的功能。
name = raw_input('please enter your name: ')
print('hello,', name)
重新执行:
[root@cen68 ~]# python cs.py
please enter your name: lwj
('hello,', 'lwj')