@wangwangheng
2015-04-01T16:15:56.000000Z
字数 770
阅读 1996
其它编程语言
命令:exit()
命令:python 文件名称.py
- 如果没有找到Python脚本文件,则会报错:
python: can't open file 'test2.py': [Errno 2] No such file or directory
- 执行Python脚本不能在Python交互模式下执行
文件名称.py
(需要把Python可执行程序加入到Path之中).py
文件的第一行加上:#!/usr/bin/env python
(相当于Windows的配置环境变量)chmod a+x 文件名称.py
./文件名称.py
使用print
加上字符串,就可以向屏幕输出制定的文字,例如:print "Hello World"
可以用逗号分开多个字符串,Python遇到一个逗号就会输出一个空格
例子:
print "Hello","World","Use Text Editor!!!"
将会输出Hello World Use Text Editor!!!
print
也可以打印整数或者计算结果
print 300 + 300
将会输出600
print "100 + 200 = ",100 + 200
将会输出100 + 200 = 300
使用raw_input
让用户输入字符串并且保存到一个变量中
例子:
>>> name = raw_input()
zhangsan
>>> print name
zhangsan
另外,使用raw_input("tips string")
,可以在让用户输入之前给予提示
例子
>>> n = raw_input('Please input your name:')
Please input your name:zhangsan
>>> print n
zhangsan