}")
获取索引值和值
l = [1, 2, 3, 4, 5, 6]
for i, e in enumerate(l):
print(f"index: {i}, value: {e}")
while...循环
一定要有逻辑判断语句来退出while循环
while 判断语句:
表达式
while True:
判断语句
表达式
跳出循环
break
停止当前循环
continue...跳过当前的执行逻辑, 立即执行下一个循环语句单元;
pass
跳过当前条件判断中的执行语句, 后续语句继续执行;
Python的异常与处理
异常
程序遇到严重错误时, 会终止程序的运行并抛出异常
def...(most recent call last):
File "", line 1, in
IndexError: list index out of range
KeyError...>> d = {"a": 1}
>>> d["b"]
Traceback (most recent call last):
File "", line 1, in
KeyError