# 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']
'''
python二次加工标准类型(包装)
最新推荐文章于 2021-02-11 05:30:27 发布