class Person(object):
__count = 0
def __init__(self, name):
self.name = name
Person.__count = Person.__count+1
p1 = Person('Bob')
p2 = Person('Alice')
print Person.__count
__count = 0
def __init__(self, name):
self.name = name
Person.__count = Person.__count+1
p1 = Person('Bob')
p2 = Person('Alice')
print Person.__count
2015-03-25
def format_name(s):
return s[0].upper()+s[1:]
print map(format_name, ['adam', 'LISA', 'barT'])
return s[0].upper()+s[1:]
print map(format_name, ['adam', 'LISA', 'barT'])
2015-03-24
print filter(lambda x:True if x and x.strip() else False, ['test', None, '', 'str', ' ', 'END'])
2015-03-23
def format_name(s):
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.title()
print map(format_name, ['adam', 'LISA', 'barT'])
2015-03-23
class Rational(object):
def __init__(self, p, q):
self.p = p
self.q = q
def __int__(self):
return self.p // self.q
def __float__(self):
return (self.p / float(self.q))
print float(Rational(7, 2))
print float(Rational(1, 3))
def __init__(self, p, q):
self.p = p
self.q = q
def __int__(self):
return self.p // self.q
def __float__(self):
return (self.p / float(self.q))
print float(Rational(7, 2))
print float(Rational(1, 3))
2015-03-23