class Student(Person):
def __init__(self, name, gender, score):
super(Student, self).__init__(name, gender)
self.score = score
def __str__(self):
return '(Student: %s, %s, %s)'%(self.name,self.gender,self.score)
__repr__=__str__
def __init__(self, name, gender, score):
super(Student, self).__init__(name, gender)
self.score = score
def __str__(self):
return '(Student: %s, %s, %s)'%(self.name,self.gender,self.score)
__repr__=__str__
2015-04-23
在json/decoder.py中提示“No JSON object could be decoded”,所以在read()方法中要返回具有json格式的原始字符串,最简单的就是[]
2015-04-23
def calc_prod(lst):
def multi(a,b):
return a*b
def reduceX():
return reduce(multi,lst)
return reduceX
f = calc_prod([1, 2, 3, 4])
print f()
def multi(a,b):
return a*b
def reduceX():
return reduce(multi,lst)
return reduceX
f = calc_prod([1, 2, 3, 4])
print f()
2015-04-22
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