Apr-13-2017, 09:20 PM
>>> class example(): ... pass >>> foo = example() >>> foo.x = 10 # new variable >>> foo.y = 20 # new variable >>> foo.sum = lambda a, b: a + b >>> foo.sum(10, 20) 30 >>> foo.sum(foo.x, foo.y) 30 >>> foo.x = 20 >>> foo.sum(foo.x, foo.y) 40 >>> class example2(): ... x = 5 ... y = 7 >>> bar = example2() >>> bar.x 5 >>> bar.x = 12 >>> bar.x 12It could be simple as this one. Why to define a method just to change a variable?