Python 解释器

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 !

 

转载于:https://www.cnblogs.com/BlueSkyyj/p/10304614.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值