[关闭]
@wangwangheng 2015-04-01T16:15:56.000000Z 字数 770 阅读 1820

Python基本使用

其它编程语言


1. 退出Python执行

命令:exit()

2. 执行Python脚本

命令:python 文件名称.py

  • 如果没有找到Python脚本文件,则会报错:python: can't open file 'test2.py': [Errno 2] No such file or directory
  • 执行Python脚本不能在Python交互模式下执行

3. 直接运行Python脚本

4. 输出

使用print加上字符串,就可以向屏幕输出制定的文字,例如:print "Hello World"

5. 输入

使用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

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注