def __cmp__(self, s):
if self.score<s.score:
return 1
elif self.score>s.score:
return -1
elif self.score==s.score:
if self.name<s.name:
return -1
else:
return 1
if self.score<s.score:
return 1
elif self.score>s.score:
return -1
elif self.score==s.score:
if self.name<s.name:
return -1
else:
return 1
2015-04-22
return'(Student:%s,%s,%s)'%(self.name,self.gender,self.score)
2015-04-22
class Person(object):
count=0
def __init__(self,name):
self.name=name
Person.count = Person.count+1
count=0
def __init__(self,name):
self.name=name
Person.count = Person.count+1
2015-04-22
我这种方法效率挺低的:
def __init__(self, num):
if num==1 :
self.numbers=[0]
elif num==2:
self.numbers=[0,1]
else :
g=Fib(num-1)
g.numbers.append(g.numbers[-1]+g.numbers[-2])
self.numbers=g.numbers
def __init__(self, num):
if num==1 :
self.numbers=[0]
elif num==2:
self.numbers=[0,1]
else :
g=Fib(num-1)
g.numbers.append(g.numbers[-1]+g.numbers[-2])
self.numbers=g.numbers
2015-04-21
class BStudent(BasketballMixin,Student):
pass
class FTeacher(FootballMixin,Teacher):
pass
pass
class FTeacher(FootballMixin,Teacher):
pass
2015-04-21
import json
class Students(object):
def read(self):
return r'["TIM","Bob","Alice"]'
s = Students()
print json.load(s)
class Students(object):
def read(self):
return r'["TIM","Bob","Alice"]'
s = Students()
print json.load(s)
2015-04-21
http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/0014186131194415d50558b7a1c424f9fb52b84dc9c965c000#0
廖老师的官网上的python
廖老师的官网上的python
2015-04-21
@classmethod
def how_many(cls):
return cls.__count
def __init__(self,name):
self.name=name
Person.__count+=1
def how_many(cls):
return cls.__count
def __init__(self,name):
self.name=name
Person.__count+=1
2015-04-20
import math
def is_sqr(x):
for i in range(1,11):
if x == (i*i):
return True
print filter(is_sqr, range(1, 101))
def is_sqr(x):
for i in range(1,11):
if x == (i*i):
return True
print filter(is_sqr, range(1, 101))
2015-04-20
def format_name(s):
return s[0].upper()+s[1:len(s)].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return s[0].upper()+s[1:len(s)].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2015-04-20
class Person(object):
count=0
def __init__(self,name):
#self.name=name
Person.count=Person.count+1
count=0
def __init__(self,name):
#self.name=name
Person.count=Person.count+1
2015-04-20
class Person(object):
pass
p1 = Person()
p1.name = 'Bart'
p2 = Person()
p2.name = 'Adam'
p3 = Person()
p3.name = 'Lisa'
L1 = [p1, p2, p3]
L2 = sorted(L1,lambda x,y:cmp(x.name,y.name))
print L2[0].name
print L2[1].name
print L2[2].name
pass
p1 = Person()
p1.name = 'Bart'
p2 = Person()
p2.name = 'Adam'
p3 = Person()
p3.name = 'Lisa'
L1 = [p1, p2, p3]
L2 = sorted(L1,lambda x,y:cmp(x.name,y.name))
print L2[0].name
print L2[1].name
print L2[2].name
2015-04-20