import math
def is_sqr(x):
return math.sqrt(x)%2==0 or math.sqrt(x)%2==1
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return math.sqrt(x)%2==0 or math.sqrt(x)%2==1
print filter(is_sqr, range(1, 101))
2017-11-13
class Person(object):
def __init__(self,name,gender,birth,job):
self.name = name
self.gender = gender
self.birth = birth
self.job = job
pass
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
print xiaoming.job
def __init__(self,name,gender,birth,job):
self.name = name
self.gender = gender
self.birth = birth
self.job = job
pass
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
print xiaoming.job
2017-11-12
拿2-7代码改了改
import functools
def cmp_ignore_case(s1, s2):
if s1.lower() > s2.lower():
return 1
if s1.lower() < s2.lower():
return -1
return 0
sorted_ignore_case = functools.partial(sorted, cmp = cmp_ignore_case)
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
import functools
def cmp_ignore_case(s1, s2):
if s1.lower() > s2.lower():
return 1
if s1.lower() < s2.lower():
return -1
return 0
sorted_ignore_case = functools.partial(sorted, cmp = cmp_ignore_case)
print sorted_ignore_case(['bob', 'about', 'Zoo', 'Credit'])
2017-11-12
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-11-12
print 'call %s() in %fs' %(f.__name__,(t2-t1))这句看不懂
2017-11-10
私有变量__xx,全局类名.__xx通过外部依然无法访问,前边课程说了实例不能访问。总之__xx不能在外部被访问,估计是一种保护。只能通过函数return的方式改变值。
2017-11-10
不看答案却是不太会做。自定义加的属性,实际是一个dict,初始化赋值的时候实际是对于dict进行迭代遍历,赋值key和value,kw.iteritems().setattr(对象名称,key,value),类似self.key=value.
2017-11-10
class Person(object):
pass
a=Person()
b=Person()
c=Person()
d=[a,b,c]
a.name="3"
b.name="2"
c.name="8"
print sorted([x.name for x in d])
pass
a=Person()
b=Person()
c=Person()
d=[a,b,c]
a.name="3"
b.name="2"
c.name="8"
print sorted([x.name for x in d])
2017-11-10