# -*- coding: UTF-8 -*- # 作者:幻灰龙 # 标题:Python 函数调用 # 描述:使用函数设计一组 “容器API”:init/set/get/exist def init(): return {} def set(dict, key, value): dict[key] = value def get(dict, key): return dict.get(key) def exist(dict, key): return dict.get(key) is not None def test(): dict = init() for i in range(10): key = "key_{}".format(i) value = i set(dict, key, value) test_key = "key_4" if exist(dict, test_key): test_value = get(dict, test_key) print("key is: {}, value is: {}".format(test_key, test_value)) if __name__ == '__main__': test()