Python 解释器 Mac Anaconda 简单介绍 -- 环境管理

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 !

猜你喜欢

转载自www.cnblogs.com/BlueSkyyj/p/10304614.html
今日推荐