# # # item 系列与[]去访问值有联系 # # obj = {"K" : "V"} # # print(obj) # 字典的对象 # # print(obj["K"]) # # # class B: # # def __getitem__(self, item): # # print("执行我了") # # return "BBBB" # # # # def __setitem__(self, key, value): # # print(key,value) # # # # b = B() # # # print(b["a"]) # # # print(b["k"]) # # b["k"] = "value" # # print(b["k"]) # # # # 在内置的模块中一些特殊的方法要求必须实现 __getitem__,__setitem__ 才能实现 # # class B: # # def __getitem__(self, item): # # return getattr(self,item) # # # # def __setitem__(self, key, value): # # setattr(self,key,value) # # def __delitem__(self, key): # # # print(key) # # delattr(self,key) # # # # b = B() # # b["k1"] = "v1" #__setitem__ # # print(b["k1"]) # __getitem__ # # del b["k1"] # __delitem__ # # print(b["k1"]) # # class C: # def __init__(self,lst): # self.lst = lst # # def __setitem__(self, key, value): # self.lst[key] = value # def __getitem__(self, item): # return self.lst[item] # def __delitem__(self, key): # self.lst.pop(key) # # c = C([1,2,3,4,5,6]) # print(c[0]) # c[0] = "999" # print(c[0]) # del c[0] # print(c.lst) # 类 # 每一个对象都是扑克牌 # 查看每个对象来查看整幅牌, # 从这一副牌中随机抽取一张牌 # 打乱这副牌顺序的功能