import math
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
2018-03-28
http://www.runoob.com/python/python-func-property.html
python @property 函数的介绍
python @property 函数的介绍
2018-03-28
import math
def is_sqr(x):
x*x<=100
print filter(is_sqr, range(1, 10))
def is_sqr(x):
x*x<=100
print filter(is_sqr, range(1, 10))
2018-03-28
这样说吧,x = f() 因为,f()返回的是一个函数g,所以,这里g就是x<x就是g ,所以直接 >>>x结果就是一个函数的位置,而x()调用x就会调用到g
2018-03-27
> a, b = 0, 1
> a, b = b, a + b
right: -->r = (b,a+b)-->r = (1,1)
left:a=r[0],b=r[1]
> a, b = b, a + b
right: -->r = (b,a+b)-->r = (1,1)
left:a=r[0],b=r[1]
2018-03-27
class Student(Person):
__slots__ = ('score')
def __init__(self, name, gender ,score):
super(Student,self).__init__(name, gender)
self.score = score
__slots__ = ('score')
def __init__(self, name, gender ,score):
super(Student,self).__init__(name, gender)
self.score = score
2018-03-27
@property
def grade(self):
if self.__score >= 80:
return 'A'
elif self.__score >= 60:
return 'B'
else:
return 'C'
def grade(self):
if self.__score >= 80:
return 'A'
elif self.__score >= 60:
return 'B'
else:
return 'C'
2018-03-27
def __str__(self):
return '(Student: %s, %s, %s)' % (self.name, self.gender, self.score)
return '(Student: %s, %s, %s)' % (self.name, self.gender, self.score)
2018-03-26
class Person(object):
def __init__(self, name):
self.name = name
xiaoming = Person("xiaoming")
xiaohong = Person(name="xiaohong")
print xiaoming.name
print xiaohong.name
print("hahaha!")
def __init__(self, name):
self.name = name
xiaoming = Person("xiaoming")
xiaohong = Person(name="xiaohong")
print xiaoming.name
print xiaohong.name
print("hahaha!")
2018-03-26
class BStudent(Student, BasketballMixin):
def __init__(self):
super(Student, self).__init__()
super(BasketballMixin, self).__init__()
def __init__(self):
super(Student, self).__init__()
super(BasketballMixin, self).__init__()
2018-03-26
import math
def is_sqr(x):
return int(math.sqrt(x))**2==x
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return int(math.sqrt(x))**2==x
print filter(is_sqr, range(1, 101))
2018-03-26
class Students(object):
def __init__(self):
pass
def read(self):
return r'["Tim", "Bob", "Alice"]'
def __init__(self):
pass
def read(self):
return r'["Tim", "Bob", "Alice"]'
2018-03-26
python 2和 python 3 通用:
L2 = sorted(L1,key = lambda x:x.name)
老师里面的答案只适用2.7及以下
L2 = sorted(L1,key = lambda x:x.name)
老师里面的答案只适用2.7及以下
2018-03-26