function sum()
a = 0
b = 0
c = 0
d = 0
i = 0
print(a + b + c + d + i)
sl = {'a': 5, 'c': 2}
sum(sl)
def set_settings(self, **kwargs):
for name, value in kwargs.items():
getattr(self, name).setText(value)
obj.set_settings(label1='one', label2='two')
obj.set_settings(**{'label1': 'one', 'label2': 'two'})
obj.label1.setText('one')
obj.label2.setText('two')
>>> def my_func(express, args):
... return eval(express % args)
...
>>> print my_func('%(a)d+%(b)d', {'a': 2, 'b': 3})
5
>>> print my_func('%(c)d*%(d)d', {'c': 4, 'd': 5})
20
>>> def my_sum(myargs):
... my_vars = {'a': 0, 'b': 0, 'c': 0, 'd': 0, 'i': 0}
... for im in myargs.keys():
... my_vars[im]=myargs[im]
... return eval('%(a)d+%(b)d+%(c)d+%(d)d+%(i)d' % my_vars)
...
>>> print my_sum({'a': 5, 'c': 2})
7
Note The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter.
def add(dic):
globals().update(dic)
print(x+y)
add({'x': 2, 'y': 3})
print(x)
print(y)
a = 10
e = 40
def function(a, e):
b = 3
c = 11
d = 20
print(a+b+c+d+e)
function(a, e)