版权声明:17602128911 https://blog.csdn.net/bus_lupe/article/details/85983374
# List继承原生列表list
class List(list):
def append(self, p):
if type(p) == str:
# 用父类添加
# list.append(self, p)
super().append(p)
else:
print('必须是字符串')
def show_mid(self):
l = int(len(self) / 2)
print(self[l])
arr = List('hello')
print(arr)
arr.show_mid()
arr.append('911')
arr.append(110)
print(arr)
'''
['h', 'e', 'l', 'l', 'o']
l
必须是字符串
['h', 'e', 'l', 'l', 'o', '911']
'''