python运行方式

(经过网络学习,整理的文章,如有侵权,私聊删除)

  1. 交互式编程
    不需要创建脚本文件,通过python解释器的交互模式来编写代码
    mac上在iTerm中输入python即可启动交互式编程。
    $ python
    Python 2.7.10 (default, Jul 30 2016, 19:40:32)
    [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.

x=int(input("please input your age"))
please input your age10
x
10

2.创建脚本文件,通过脚本参数调用解释器开始执行脚本,直到脚本顺序执行完毕, 解释器不再有效。
创建python文件test.py 文件内容:print 'hello python'
$ python test.py

3.直接运行python脚本。
创建python文件test.py,文件内容:

! /usr/bin/python #python安装目录 可以用which python查看

print 'hello python'

$chmod +x test.py #给脚本文件添加可执行权限
$./test.py

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容