Python 基础
150 道练习
150 道 Python 练习覆盖语法基础、函数、列表字典、异常处理与面向对象,附预期输出预测与逐行讲解。
- 1
Python 变量 Naming 测验
测试你的 knowledge 的 Python 变量 naming 规则 and 约定.
单选题 简单 - 2
Assign Python 变量
练习 using 正确 assignment 运算符到 设置 Python 变量.
填空题 入门 - 3
Python 动态输入
检查你的理解的 Python's 动态输入系统.
概念检查 中等 - 4
Python 函数定义测验
测试你的 knowledge 的 keyword used 到定义函数 in Python.
单选题 入门 - 5
Predict Python 函数输出
Predict 输出的 简单 Python 函数那个 squares 数字.
预测输出 入门 - 6
Predict Python 如果/elif/else 输出
Predict 输出的 Python 如果/elif/else 链那个 classifies 数字.
预测输出 入门 - 7
完整 Python for 循环
Fill in 空白到 制作 Python for 循环 iterate over 范围的 数字 0 到 4.
填空题 入门 - 8
Python Integer Division Result
测验 on result 的 // floor-division 运算符 in Python.
单选题 简单 - 9
Python Modulo 运算符
测验 on % modulo 运算符 and remainder calculation.
单选题 简单 - 10
Python 布尔值类型
测验 on bool 类型 and truthy/falsy 值 in Python.
单选题 简单 - 11
Python 字符串 Immutability
测验 on whether Python 字符串是 可变 or 不可变.
单选题 中等 - 12
Python 列表 Slicing
测验 on 列表 slicing 语法 and behavior.
单选题 简单 - 13
Python 列表 append 对比 extend
测验 on difference 之间 append and extend for 列表.
单选题 中等 - 14
Python Dictionary 键类型
测验 on 哪个类型能 是 used as dictionary 键.
单选题 中等 - 15
Python 默认实参
测验 on 默认参数值 in Python 函数.
单选题 简单 - 16
Python 可变默认实参 Pitfall
测验 on classic 可变默认实参 bug.
单选题 中等 - 17
Python 虽然循环条件
测验 on 虽然循环 termination 条件.
单选题 简单 - 18
Python for 循环使用范围
测验 on 范围() 使用 two 实参.
单选题 简单 - 19
Python 字符串方法
测验 on 字符串方法如 upper and strip.
单选题 简单 - 20
Python Tuple Unpacking
测验 on tuple unpacking 到多个变量.
单选题 简单 - 21
Python 设置属性
测验 on 设置 behavior — uniqueness and 排序.
单选题 中等 - 22
Python try/except Behavior
测验 on 如何 try/except 块工作.
单选题 简单 - 23
Python self 参数
测验 on self 参数 in Python 方法.
单选题 中等 - 24
Python __init__ 方法
测验 on constructor 方法 __init__.
单选题 简单 - 25
Python 导入语句
测验 on importing 模块 in Python.
单选题 简单 - 26
Python 列表 Comprehension 语法
测验 on 读取 and 理解列表 comprehensions.
单选题 中等 - 27
Python Lambda 语法
测验 on anonymous lambda 函数 in Python.
单选题 中等 - 28
Python File 打开模式
测验 on file 打开模式如 'r', 'w', ''.
单选题 简单 - 29
Python datetime 模块
测验 on 获取 current date and 时间.
单选题 简单 - 30
Python JSON Parsing
测验 on converting JSON 字符串到 Python 对象.
单选题 简单 - 31
Python Generator 函数
测验 on generators and yield keyword.
单选题 中等 - 32
Python Decorator Purpose
测验 on 什么 decorators 做 in Python.
单选题 中等 - 33
Python 继承基础
测验 on 类继承 and 方法 resolution.
单选题 中等 - 34
Python 使用语句
测验 on 使用语句 and 上下文 managers.
单选题 简单 - 35
Python 类型 Hints
测验 on 类型提示语法 for 函数 signatures.
单选题 中等 - 36
Python Regex 模块
测验 on re 模块 and 模式 matching.
单选题 中等 - 37
Python PEP 8 样式
测验 on PEP 8 naming 约定.
单选题 简单 - 38
Predict 变量 Reassignment
Predict 输出之后变量 reassignment.
预测输出 入门 - 39
Predict 字符串 Concatenation
Predict 输出的 字符串 concatenation 使用 +.
预测输出 入门 - 40
Predict f-字符串输出
Predict 输出的 f-字符串使用表达式.
预测输出 简单 - 41
Predict 列表 Indexing
Predict 输出的 列表 indexing 使用正 and 负索引.
预测输出 简单 - 42
Predict 列表方法输出
Predict 输出之后 pop and append 操作.
预测输出 简单 - 43
Predict Dictionary Access
Predict 输出的 dictionary 键 access and 获取().
预测输出 简单 - 44
Predict for 循环总和
Predict 输出的 for 循环那个 accumulates 总和.
预测输出 简单 - 45
Predict 函数使用默认 Arg
Predict 输出当 calling 函数使用 and 不使用实参.
预测输出 简单 - 46
Predict 字符串拆分
Predict 输出的 拆分字符串.
预测输出 简单 - 47
Predict Nested 如果/else
Predict 输出的 nested conditional logic.
预测输出 中等 - 48
Predict 列表 Comprehension 使用筛选
Predict 输出的 列表 comprehension 使用如果 clause.
预测输出 中等 - 49
Predict Tuple Packing and Unpacking
Predict 输出的 tuple packing and unpacking.
预测输出 简单 - 50
Predict 设置操作
Predict 输出的 union and intersection on 设置.
预测输出 中等 - 51
Predict 多个返回值
Predict 输出的 函数 returning tuple.
预测输出 中等 - 52
Predict try/except/最后
Predict 输出当 异常是 caught.
预测输出 中等 - 53
Predict 类实例输出
Predict 输出的 创建 and using 类实例.
预测输出 中等 - 54
Predict Lambda 使用排序
Predict 输出的 排序使用 lambda 键.
预测输出 中等 - 55
Predict Generator 输出
Predict 输出的 consuming generator 使用列表().
预测输出 中等 - 56
Predict Dict Comprehension
Predict 输出的 dictionary comprehension.
预测输出 中等 - 57
Predict 字符串 Repetition
Predict 输出的 multiplying 字符串通过 integer.
预测输出 入门 - 58
Fill: 列表 Append
Fill in 方法到 添加元素到 端的 列表.
填空题 入门 - 59
Fill: 字符串长度
Fill in 函数到 获取长度的 字符串.
填空题 入门 - 60
Fill: Dict 获取使用默认
Fill in 方法到 safely access dictionary 键.
填空题 简单 - 61
Fill: 字符串 Uppercase
Fill in 方法到 convert 字符串到 uppercase.
填空题 入门 - 62
Fill: Break 从循环
Fill in keyword 到 exit 循环 early.
填空题 入门 - 63
Fill: 函数返回
Fill in keyword 到返回值 从函数.
填空题 入门 - 64
Fill: 列表排序
Fill in 方法到 排序列表 in 位置.
填空题 简单 - 65
Fill: 字符串 Replace
Fill in 方法到 replace substring.
填空题 简单 - 66
Fill: Except Clause
Fill in keyword 到 catch 异常.
填空题 简单 - 67
Fill: 类定义
Fill in keyword 到定义类.
填空题 入门 - 68
Fill: 从导入
Fill in keyword 到导入特定 name 从模块.
填空题 简单 - 69
Fill: 列表 Insert
Fill in 方法到 insert 元素 at 特定位置.
填空题 简单 - 70
Fill: Dict 项 Iteration
Fill in 方法到 iterate over 键-值 pairs.
填空题 中等 - 71
Fill: 字符串连接
Fill in 方法到 连接列表的 字符串使用 separator.
填空题 中等 - 72
Fill: Continue Keyword
Fill in keyword 到 skip REST 的 current iteration.
填空题 简单 - 73
Fill: 打开 File for 读取
Fill in 模式到 打开 file for 读取.
填空题 简单 - 74
Fill: JSON Dumps
Fill in 函数到 convert Python 对象到 JSON 字符串.
填空题 简单 - 75
Fill: Lambda Keyword
Fill in keyword 到创建 anonymous 函数.
填空题 中等 - 76
Fill: 设置添加
Fill in 方法到 添加元素到 设置.
填空题 简单 - 77
Fill: Raise 异常
Fill in keyword 到 manually 触发异常.
填空题 中等 - 78
查找 Mistake: Missing Colon
查找语法错误 in 如果语句.
找错误 入门 - 79
查找 Mistake: Missing Indentation
查找 indentation 错误 in 函数请求体.
找错误 入门 - 80
查找 Mistake: 字符串 + Int Concatenation
查找类型错误 in 字符串 concatenation.
找错误 简单 - 81
查找 Mistake: Off-通过-One 索引
查找 IndexError in 列表 access.
找错误 简单 - 82
查找 Mistake: Missing 键 Access
查找 KeyError in dictionary access.
找错误 简单 - 83
查找 Mistake: Using Keyword as 变量
查找语法错误从 using reserved keyword.
找错误 简单 - 84
查找 Mistake: Division 通过零
查找 ZeroDivisionError in code.
找错误 简单 - 85
查找 Mistake: 修改列表期间 Iteration
查找 logical 错误的 移除项 虽然 iterating.
找错误 中等 - 86
查找 Mistake: 可变默认实参
查找 bug 使用可变默认实参.
找错误 中等 - 87
查找 Mistake: Comparing 使用 =
查找错误从 using = 相反的 == for comparison.
找错误 简单 - 88
查找 Mistake: Missing self 参数
查找错误 in 方法定义 missing self.
找错误 中等 - 89
查找 Mistake: File 不关闭
查找 resource leak 从不 关闭 file.
找错误 中等 - 90
查找 Mistake: 无限虽然循环
查找 bug causing 无限循环.
找错误 简单 - 91
查找 Mistake: 错误导入 Name
查找 ImportError 从错误模块 name.
找错误 简单 - 92
查找 Mistake: Bare Except Clause
查找坏 练习的 bare except 那个 catches 一切.
找错误 中等 - 93
概念: Interpreted 对比 Compiled
检查理解的 Python 是 interpreted language.
概念检查 中等 - 94
概念: 动态输入
检查理解的 Python's 动态类型系统.
概念检查 中等 - 95
概念: 类对比实例
检查理解的 difference 之间类 and 实例.
概念检查 中等 - 96
概念: Generator 对比列表
检查理解的 为什么 generators 是 memory-efficient.
概念检查 中等 - 97
概念: 为什么 Use 模块
检查理解的 purpose 的模块.
概念检查 简单 - 98
概念: 为什么 Catch 异常
检查理解的 purpose 的异常 handling.
概念检查 简单 - 99
概念: 继承 Purpose
检查理解的 为什么我们 use 继承.
概念检查 中等 - 100
概念: Readability 原则
检查理解的 Python's readability philosophy.
概念检查 简单 - 101
Python 缩进
Python 如何定义代码块?
单选题 入门 - 102
Python 变量类型
Python 中变量类型如何确定?
单选题 入门 - 103
列表与元组
列表和元组的关键区别是什么?
单选题 入门 - 104
字典访问
{} 用什么存储值?
单选题 入门 - 105
字符串格式化
Python 中格式化字符串的现代方式是什么?
单选题 简单 - 106
列表推导
[x*2 for x in range(3)] 产生什么?
单选题 简单 - 107
Lambda 语法
Python 中 lambda 是什么?
单选题 简单 - 108
def 与 lambda
何时应使用 def 而非 lambda?
单选题 简单 - 109
异常处理
Python 中如何捕获异常?
单选题 入门 - 110
with 语句
with 语句做什么?
单选题 中等 - 111
Python None
Python 中 None 是什么?
单选题 入门 - 112
可变默认参数
为何 def f(x=[]) 危险?
单选题 中等 - 113
全局与局部
Python 如何确定变量作用域?
单选题 中等 - 114
切片语法
[1,2,3,4,5][1:4] 返回什么?
单选题 简单 - 115
字典 get 方法
{}.get("missing") 返回什么?
单选题 简单 - 116
for-else 构造
for 循环的 else 子句何时运行?
单选题 中等 - 117
yield 关键字
Python 中 yield 做什么?
单选题 中等 - 118
装饰器用途
什么是 Python 装饰器?
单选题 中等 - 119
类 init 方法
Python 类中 __init__ 是什么?
单选题 入门 - 120
self 参数
Python 方法中 self 是什么?
单选题 入门 - 121
import 语法
from math import sqrt 做什么?
单选题 简单 - 122
字符串方法
"hello".upper() 返回什么?
单选题 入门 - 123
range 函数
list(range(2, 10, 2)) 产生什么?
单选题 简单 - 124
类型提示用途
Python 类型提示用于什么?
单选题 中等 - 125
文件读取行
如何安全地逐行读取文件?
单选题 简单 - 126
in 运算符
"a" in ["a", "b"] 返回什么?
单选题 入门 - 127
集合数据结构
Python 集合有什么独特之处?
单选题 中等 - 128
zip 函数
list(zip([1,2], ["a","b"])) 返回什么?
单选题 中等 - 129
map 函数
list(map(str, [1, 2, 3])) 返回什么?
单选题 中等 - 130
enumerate 函数
list(enumerate(["a", "b"])) 返回什么?
单选题 简单 - 131
Python print
预测输出。
预测输出 入门 - 132
变量赋值
预测输出。
预测输出 入门 - 133
列表操作
预测输出。
预测输出 入门 - 134
字符串方法
预测输出。
预测输出 简单 - 135
字典访问
预测输出。
预测输出 简单 - 136
if-elif-else
预测输出。
预测输出 简单 - 137
for 循环求和
预测输出。
预测输出 简单 - 138
列表推导
预测输出。
预测输出 简单 - 139
元组解包
预测输出。
预测输出 简单 - 140
字符串格式化
预测输出。
预测输出 简单 - 141
布尔逻辑
预测输出。
预测输出 简单 - 142
列表切片
预测输出。
预测输出 简单 - 143
字典 items
预测输出。
预测输出 中等 - 144
sorted 函数
预测输出。
预测输出 中等 - 145
字符串 split
预测输出。
预测输出 简单 - 146
max 函数
预测输出。
预测输出 简单 - 147
abs 函数
预测输出。
预测输出 入门 - 148
type 函数
预测输出。
预测输出 简单 - 149
集合运算
预测输出。
预测输出 中等 - 150
字符串 join
预测输出。
预测输出 中等
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。