Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # b_dict_functional.py
- result = {}
- def fn(x):
- result.update ({
- 'a': x * 5,
- 'b': x + 7,
- 'c': x - 2,
- 5 : x == 5,
- 0 : x * 20
- })
- 0
- fn(5)
- print result.get('b') # 12
- print result.get(0) # 100
- print result.get(5) # True
- print result.get('x') # None
- x=100
- print result.get(x) # None
- result['z'] = 'Zzz...'
- print result # {'a': 25, 0: 100, 'c': 3, 'b': 12, 5: True, 'z': 'Zzz...'}
- fn(100)
- print result # {'a': 500, 0: 2000, 'c': 98, 'b': 107, 5: False, 'z': 'Zzz...'}
- print result.get('z') # 'Zzz...'
- print result['c'] # 98
- print result['x'] # KeyError: 'x'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement