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
最新回答 / qq_龙_18
应该是你使用错误了!那个count放在类里面就是类的属性了!不是全局变量!count=0class Person(object): def __init__(self,name): global count count+=1 self.name=namep1 = Person('Bob')print countp2 = Person('Alice')print countp3 = Person('Tim')print count你这样试一试
2018-03-27
这样说吧,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