2、Python解释器

Python解释器

  • Linux/Unix的系统上,Python解释器通常被安装在/usr/local/bin/python3.x这样的有效路径(目录)里。
  • 我们可以将路径/usr/local/bin添加到您的Linux/Unix操作系统的环境变量中,这样您就可通过shell 终端输入下面的命令来启动 Python 。
python3.x
  • 在Windows系统下你可以通过以下命令来设置Python的环境变量,假设你的Python安装在C:\Python36下:
set path=%path%;C:\python36

交互式编程

  • 我们可以在命令提示符中输入“Python”命令来启动Python解释器:
python
  • 执行以上命令后,出现如下窗口信息:
C:\Users\Administrator>python
Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 15 2017, 03:27:45)
1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
  • 在python提示符中输入以下语句,然后按回车键查看运行效果:
print('hello Python!')
  • 以上命令执行结果为:
hello Python!
  • 当键入一个多行结构时,续行是必须的,我们可以看如下if语句:
>>> the_world_is_flat = True
>>> if the_world_is_flat:
...    print('Be careful not to fall off!')
...
Be careful not to fall off!
>>>

脚本式编程

  • 将如下代码拷贝至hello.py文件中:
print('hello Python!')
  • 通过以下命令执行该脚本:
python hello.py
  • 输出结果为:
hello Python!
  • 在Linux/Unix系统中,你可以在脚本顶部添加以下命令让Python脚本可以向SHELL脚本一样可直接执行:
#! /usr/bin/env python3.6
  • 然后修改脚本权限,使其有执行权限,命令如下:
chmod 755 hello.py
  • 执行以下命令:
./hello.py
  • 输出结果为:
hello Python!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值