def count():
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(f())
return fs
f1, f2, f3 = count()
print f1, f2, f3
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(f())
return fs
f1, f2, f3 = count()
print f1, f2, f3
2017-09-05
def __cmp__(self, s):
if self.score < s.score:
return 1
elif self.score > s.score:
return -1
else:
return cmp(self.name,s.name)
if self.score < s.score:
return 1
elif self.score > s.score:
return -1
else:
return cmp(self.name,s.name)
2017-09-05
我个人觉得吧,编程这种东西就是要学会看报错以及吸取他人经验才能牢牢记住啊,如果顺风顺水的一路学下来到最后能记得住什么呢?
2017-09-05
import math
def is_sqr(x):
return math.modf(math.sqrt(x))[0]<=0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return math.modf(math.sqrt(x))[0]<=0
print filter(is_sqr, range(1, 101))
2017-09-05
def cmp_ignore_case(s1, s2):
if s1.lower() < s2.lower():
return -1
if s1.lower() > s2.lower():
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1.lower() < s2.lower():
return -1
if s1.lower() > s2.lower():
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2017-09-04
#coding=utf-8
def __str__(self):
a = gcd(self.p,self.q)
return '%s/%s' % (self.p/a,self.q/a)
__repr__ = __str__
def gcd(a,b):
#余数为0的除数即为最大公约数
if b==0:
return a
return gcd(b,a%b)
def __str__(self):
a = gcd(self.p,self.q)
return '%s/%s' % (self.p/a,self.q/a)
__repr__ = __str__
def gcd(a,b):
#余数为0的除数即为最大公约数
if b==0:
return a
return gcd(b,a%b)
2017-09-04
要是没有其他面向对象语言的基础,这课程还真的有点看不懂,但是想想这还是基础,坚持学完吧,后面路还很长
2017-09-04
print filter(lambda s:s and len(s.strip()) > 0, ['test', None, '', 'str', ' ', 'END'])
2017-09-04
import math
def is_sqr(x):
return x%math.sqrt(x)==0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return x%math.sqrt(x)==0
print filter(is_sqr, range(1, 101))
2017-09-04