Python编程 Day01

Python编程

准备环境

1、检查python版本
运行终端,输入执行:python

shiyanlou:~/ $ python                                                 [8:40:30]
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

注意:>>> 提示符后可直接输入运行python指令
退出Python并返回终端窗口,可按 Ctrl+D 或 执行命令exit()

2、vim 编辑器,运行Hello World程序
直接进入python行输入命令

>>> print("Hello World!")
Hello World!

或者 写入脚本再运行

shiyanlou:~/ $ vim hello_world.py                                     [9:08:44]
shiyanlou:~/ $ chmod +x hello_world.py                                [9:11:02]
shiyanlou:~/ $ ./hello_world.py                                       [9:11:17]
Hello World!
shiyanlou:~/ $                                                        [9:11:25]
// hello_world.py
#!/usr/bin/env python3
print("Hello World!")

输入 i 进入插入模式,按 esc 退出插入模式,输入 :wq 退出编辑器

遇到问题1:当执行py脚本时提示以下错误,是因为当前处于python命令输入行,只能执行python命令。
而执行py脚本,则应在终端(cmd、linux)进行调用。

>>> ./hello_world.py
  File "<stdin>", line 1
    ./hello_world.py
    ^
SyntaxError: invalid syntax

vim编辑器键盘图

变量和数据类型

关键字和标识符

>>>help()
help>keywords
Here is a list of the Python keywords.  Enter any keyword to get more help.
False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not
shiyanlou:~/ $ python3
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值