import math
def is_sqr(x):
for i in range(1,11):
if i*i==x:
return x
print filter(is_sqr, range(1,101))
def is_sqr(x):
for i in range(1,11):
if i*i==x:
return x
print filter(is_sqr, range(1,101))
2018-08-19
class Person(object):
def __init__(self, name, sex, birth, **kw):
self.name = name
self.sex = sex
self.birth = birth
for key,value in kw.items():
setattr(self,key,value)
def __init__(self, name, sex, birth, **kw):
self.name = name
self.sex = sex
self.birth = birth
for key,value in kw.items():
setattr(self,key,value)
2018-08-19
class Person(object):
def __init__(self, name, sex, birth, **kw):
self.name = name
self.sex = sex
self.birth = birth
setattr(self, kw.items()[0][0], kw.items()[0][1])
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
print xiaoming.job
def __init__(self, name, sex, birth, **kw):
self.name = name
self.sex = sex
self.birth = birth
setattr(self, kw.items()[0][0], kw.items()[0][1])
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
print xiaoming.job
2018-08-19
没事老师没讲的不要着急,这时候就是发挥侦查功能的时候,首先到网上查一圈(花时间),没有的话,这时候就可以查一下同学的代码,然后根据提示继续网上查,然后你就会理解了。这也没啥.... 我觉得挺好的我查出好多骚东西
2018-08-18
1.高阶函数:函数调用函数
2.闭包 : 外层是带参数的函数,内层函数调用了外层的参数
3.装饰器 :就是高阶函数的应用,把函数做参数调用,包装一下,再返回函数
4.带参数的装饰器:就是外面又套了一层的函数
log_decorator = log('Debug')
log = log_decorator(log)
2.闭包 : 外层是带参数的函数,内层函数调用了外层的参数
3.装饰器 :就是高阶函数的应用,把函数做参数调用,包装一下,再返回函数
4.带参数的装饰器:就是外面又套了一层的函数
log_decorator = log('Debug')
log = log_decorator(log)
2018-08-16
import math
def is_sqr(x):
return x and math.sqrt(x)==math.ceil(math.sqrt(x))
###math.sqrt(x)如果是可以开方,是浮点型,,##math.ceil(math.sqrt(x))是向上取整,其原理就是去零,如果两个相##等即可
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return x and math.sqrt(x)==math.ceil(math.sqrt(x))
###math.sqrt(x)如果是可以开方,是浮点型,,##math.ceil(math.sqrt(x))是向上取整,其原理就是去零,如果两个相##等即可
print filter(is_sqr, range(1, 101))
2018-08-13
class Person(object):
count = 0
def __init__(self,name):
self.name = name
Person.count += 1
p1 = Person('Bob')
print Person.count
p2 = Person('Alice')
print Person.count
p3 = Person('Tim')
print Person.count
count = 0
def __init__(self,name):
self.name = name
Person.count += 1
p1 = Person('Bob')
print Person.count
p2 = Person('Alice')
print Person.count
p3 = Person('Tim')
print Person.count
2018-08-12
import os
print os.path.isdir(r'/data/webroot/resource/python')
print os.path.isfile(r'/data/webroot/resource/python/test.txt') or True
print os.path.isdir(r'/data/webroot/resource/python')
print os.path.isfile(r'/data/webroot/resource/python/test.txt') or True
2018-08-12