导入tushare和pandas
- pip install tushare -i https://pypi.tuna.tsinghua.edu.cn/simple 清华镜像
- pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple 清华镜像
- try except except 。。。。。else(执行except’外的) finally (总是执行)
- raise 抛出自定义异常
class MyArray():
def __init__(self):
self.t = ()
def add(self,value):
lt = list(self.t)
lt.append(value)
self.t = tuple(lt)
def remove(self,value):
lt = list(self.t)
try:
lt.remove(value)
except ValueError as ve:
print("友好提示/对错误信信息得处理")
except ZeroDivisionError as e:
print("友好提示/对错误信信息得处理")
else:
print("友好提示/对错误信信息得处理")
finally:
self.t = tuple(lt)
def display(self):
print(self.t)
my_array.a()
class AgeOutOfBoundError(ValueError):
def __init__(self,message):
super().__init__(message)
def set_age(age):
if age>120:
raise ValueError("年龄太大了")
set_age(121)