class F:
def __init__(self):
self.args = ['hello', 'world']
def __getitem__(self, item):
return self.args[item]
res = F()
print(res.args[0]) # 结果是hello,操作列表
class S:
def __init__(self):
self.args = {'name': 'jack', 'age': 18}
def __getitem__(self, item):
return self.args[item]
msg = S()
print(msg.args['name']) # 结果是jack,字典列表