1
With the follow code
def parallel(x, y=1): return float(x * y) / (x + y) parallel(2)
the follow happens:
2
With the two different definitions:
def first(n, m): "Bernoulli numbers computed as 1**m + 2**m + ... + n**m" return sum(map(lambda n: n**m, range(1,n+1))) def second(n): # Bernoulli numbers computed as 1**m + 2**m + ... + n**m return sum(map(lambda n: n**m, range(1,n+1)))
3
With the two above code
help(first)
dir(first)
4
class Mammal(): def number_of_legs(self): return 4 class Dog(Mammal): pass class Human(Mammal): def number_of_legs(self): return 2 fido = Dog() anna = Human()
we have:
5
With the above code we have:
fido.number_of_legs()
6
We have that
7
class Myint(): def __init__(self, integer): self.integer = long(integer) def __add__(self, integer): return long(str(self.integer) + str(integer)) a = Myint(1) b = a + 3 c = b + 4
we have
8
We have
True __add__ False
True or False
9
for n in range(10): if n == 2 or n == 6: continue elif n == 8: break print(n) else: print("Hello")
10
def bum(): n = 1 while True: if not n % 5 or 5 in map(int, list(str(n))): yield 'bum' else: yield n n += 1 bums = bum() for b in bums: print(b)