美文网首页
python运行方式

python运行方式

作者: 郑园园_02f1 | 来源:发表于2017-06-13 13:25 被阅读0次

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

  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

相关文章

网友评论

      本文标题:python运行方式

      本文链接:https://www.haomeiwen.com/subject/syjdqxtx.html