【python】编写并运行第一个python文件
使用编辑器NodePad++
1、输出print
输入print(‘hello, world’),并保存为test.py。存放位置D:/testPy/test.py
打开cmd命令,cd到文件存放位置,然后输入python test.py即可执行该py文件
2、输入input
将test.py内容修改为:
name = input()
print(‘hello,’, name)
即用户先输入name,然后程序输出hello,XX
但是直接输入字符后会报错,图中的第2项:name is not defined
原因:
对于 input() ,它希望能够读取一个合法的 python 表达式,即你输入字符串的时候必须使用引号将它括起来,否则它会引发一个 SyntaxError
而raw_input()会将所有输入作为字符串看待,返回字符串类型