Skip to content

Latest commit

 

History

History
172 lines (108 loc) · 3.36 KB

File metadata and controls

172 lines (108 loc) · 3.36 KB
Error in user YAML: (<unknown>): found a tab character that violate indentation while scanning a plain scalar at line 3 column 3
---
- oeasy Python 0054
- 这是 oeasy 系统化 Python 教程,从基础一步步讲,扎实、完整、不跳步。愿意花时间学,就能真正学会。
- 本教程同步发布在: 
	- 个人网站: `https://oeasy.org` 
	- 蓝桥云课: `https://www.lanqiao.cn/courses/3584` 
	- GitHub: `https://github.com/overmind1980/oeasy-python-tutorial` 
	- Gitee: `https://gitee.com/overmind1980/oeasypython` 
---

python有哪些关键字_keyword_list_列表_reserved_words

回忆上次内容

  • 配套视频
  • hello world
    • 不是 从来就有的
    • 来自于 c语言
  • print、小括号 和 双引号
    • 也来自于 c语言

图片描述

  • python 标识符 的 命名规则
    • 依然 完全 学习 c语言 惯例

图片描述

  • 需要满足 isidentifier() 之后
    • 标识符一定 能当变量用 吗?

询问

图片描述

  • 关键字 不能用做标识符

    • 举例用的是if
  • if 真 不能做 标识符吗?

    • 去游乐场试试

试试

"if".isidentifier()
  • 是否是 合法的 标识符?

图片描述

  • 符合 标识符 规则
if = 0
  • 尝试赋值

图片描述

  • 出了SyntaxError
    • 符合 标识符条件
    • 但不能 用作变量

图片描述

  • if 在哪里见过??🤔

那片黑暗森林

图片描述

  • for、in、 if 都是红颜色 诶
    • 都是关键字吗?
for num in range(0, 128):
    if num % 8 == 0:
        print()
    print(chr(num), end="\t")
  • 还有那些单词
    • 是关键字呢?

询问

图片描述

  • 尝试 运行代码

关键字列表

import keyword
print(keyword.kwlist)  # 打印 Python 的所有关键字
  • 见到了很多 老朋友

图片描述

  • 原来他们都是 关键字
    • 比如 import 是
    • 用来导入 的
    • keyword(关键字)

图片描述

  • 再试试这个True

True

  • 从 标识符命名规则 来说
    • 字符串"True" 符合命名规则

图片描述

  • 但是True
    • 有特殊含义
    • 属于关键字
    • 不能 再被 声明 为变量

图片描述

  • 什么是 关键字?

关键字

  • 关键字(keywords)
    • 是具有特定含义和用途的保留字

图片描述

  • 啥 又是保留字?

保留字

  • 保留起来 有专门用处的字
    • 就是 保留字(reserved words)
    • 也叫 关键字(key words)

图片描述

总结

  • 这次 了解了
    • 关键字列表
    • keywords list

图片描述

  • 关键字 不能做 标识符

  • 除了 关键字(keywords)之外

    • 还有啥 不适合 做标识符 吗?🤔
  • 我们下次再说!👋

  • 配套视频


  • 本文来自 oeasy Python 系统教程。
  • 想完整、扎实学 Python,
  • 搜索 oeasy 即可。