"""
1.异常处理的使用:
1) 列表超出索引: list_data = [1, 2, 3] => list_data[3]
2) 定义一个元组: tuple_data = (1, 2, 3) => tuple_data[2] = 10
3) 定义一个字典:dict_data = {1: 2, 2: 3} => dict_data[3]
2.文件操作:
新建一个文件: python0922.txt => Today I learned Exception and Open File.
复制当前这个文件Python0922.txt,粘贴到当前路径下:且新的文件名:python0924.txt
"""
try:
list_data = [1, 2, 3]
list_data[3]
except:
print("超出范围")
try:
tuple_data = (1, 2, 3)
tuplr_data[2] = 10
except:
print("没有被定义")
try:
dict_data = {1: 2, 2: 3}
dict_data[3]
except:
print("666")
file_obj = open("python0922.txt", encoding="utf-8")
Python(作业5)
最新推荐文章于 2024-08-15 01:55:01 发布