class testsetandget:
    kk = {};  
    def __getitem__(self, key):  
        return self.kk[key];  
    def __setitem__(self, key, value):  
        self.kk[key] = value;

a = testsetandget()
a['first'] = 1
print a['first']

a.__setitem__('second', 2)
print a.__getitem__('second')
print a['second']

输出:

1

2

2

相关文章:

  • 2021-10-12
  • 2022-12-23
  • 2021-08-25
  • 2021-05-19
  • 2021-11-19
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-12
  • 2022-12-23
  • 2022-01-10
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
相关资源
相似解决方案