#from _future_ import unicode_literals
s = u'am I an unicode?'
print isinstance(s, unicode)
得把导入注释上,然后加u
s = u'am I an unicode?'
print isinstance(s, unicode)
得把导入注释上,然后加u
2016-04-25
import math
def is_sqr(x):
return int(math.sqrt(x)) == math.sqrt(x)
print filter(is_sqr, range(1, 100))
def is_sqr(x):
return int(math.sqrt(x)) == math.sqrt(x)
print filter(is_sqr, range(1, 100))
2016-04-24
@score.getter
def grade(self, score):
if score>=80:
return 'A'
elif score>=60:
return 'B'
else:
return 'C'
def grade(self, score):
if score>=80:
return 'A'
elif score>=60:
return 'B'
else:
return 'C'
2016-04-24
详细解释。http://blog.csdn.net/u012965373/article/details/51233682
2016-04-24
def calc_prod(lst):
def lazy_calc_prod():
def prod(x, y):
return x * y
return reduce(prod, lst)
return lazy_calc_prod
f = calc_prod([1, 2, 3, 4])
print f()
def lazy_calc_prod():
def prod(x, y):
return x * y
return reduce(prod, lst)
return lazy_calc_prod
f = calc_prod([1, 2, 3, 4])
print f()
2016-04-24
import json
class Students(object):
def read(self):
return r'["Tim","Bob","Alice"]'
s = Students()
print json.load(s)
class Students(object):
def read(self):
return r'["Tim","Bob","Alice"]'
s = Students()
print json.load(s)
2016-04-24
def is_sqr(x):
y = int(math.sqrt(x))
if x == y * y:
return x
y = int(math.sqrt(x))
if x == y * y:
return x
2016-04-24
class Person(object):
def __init__(self, name, gender):
self.name = name
self.gender = gender
s = Student('Bob', 'Male')
li=filter(lambda x: not (x[0]=='_'),dir(s))
print li
def __init__(self, name, gender):
self.name = name
self.gender = gender
s = Student('Bob', 'Male')
li=filter(lambda x: not (x[0]=='_'),dir(s))
print li
2016-04-23