首页 > 编程语言 > 详细

Python 解释器

时间:2019-01-22 17:06:33      阅读:181      评论:0      收藏:0      [点我收藏+]

Python 解释器

关于python 环境 这里不再介绍,可参考以下介绍:

Mac Anaconda 简单介绍 -- 环境管理

交互式编程

我们可以在命令提示符中输入"python"命令来启动Python解释器:

(Adil) yangyaojundeMacBook-Pro:PyWeb yyj$ python
Python 3.7.1 (default, Oct 23 2018, 14:07:42) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

在 python 提示符中输入以下语句,然后按回车键查看运行效果:

print ("Hello, Python!");

 

以上命令执行结果如下:

Hello, Python!

 

脚本式编程

新建 test.py文件

# FileName : test.py
# Author   : Adil
# DateTime : 2019/1/22 4:04 PM
# SoftWare : PyCharm


print(hello python !)

 

通过以下命令执行该脚本:

 

python test.py

输出结果为:

(Adil) yangyaojundeMacBook-Pro:PyWeb yyj$ python test.py 
hello python !

在Linux/Unix系统中,你可以在脚本顶部添加以下命令让Python脚本可以像SHELL脚本一样可直接执行:

#! /Users/yyj/anaconda3/envs/Adil/bin/python

修改后如下:

#! /Users/yyj/anaconda3/envs/Adil/bin/python
# 以上为python 环境变量,通过 which python 获取

# FileName : test.py
# Author   : Adil
# DateTime : 2019/1/22 4:04 PM
# SoftWare : PyCharm


print(hello python !)

然后修改脚本权限,使其有执行权限,命令如下:

$ chmod +x test.py

 

执行以下命令:

./test.py

输出结果为:

(Adil) yangyaojundeMacBook-Pro:PyWeb yyj$ ./test.py 
hello python !

 

Python 解释器

原文:https://www.cnblogs.com/BlueSkyyj/p/10304614.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!