Creating class in python without using class keyword

add2 = lambda x,y: x+y sub2 = lambda x,y: x-y mul2 = lambda x,y: x*y # Second parameter is tuple, used for inheriting classes # Third parameter is dict, used for defining variables and functions myclass = type('myclass', (), {'var1': 10, 'add': add2, 'sub': sub2, 'mul': mul2}) myinstance = myclass() print(myinstance.add(10,20)) print(myinstance.sub(10,20)) print(myinstance.mul(10,20))

ऑक्टोबर 2, 2013 · 1 min · 53 words · शंतनू

Reversing the binary of the given number in python

>>> a=int(input('Enter base 10 natural number: ')) Enter base 10 natural number: 42 >>> b = bin(a) >>> a = int(b[:2]+b[2:][::-1], 2) >>> a 21

सप्टेंबर 30, 2013 · 1 min · 25 words · शंतनू