try:
import json
except ImportError:
import simplejson as json
print json.dumps({'python':2.7})
import json
except ImportError:
import simplejson as json
print json.dumps({'python':2.7})
2017-08-03
import math
def is_sqr(x):
t= int(math.sqrt(x))
if t*t==x:
return x
print filter(is_sqr, range(1, 101))
def is_sqr(x):
t= int(math.sqrt(x))
if t*t==x:
return x
print filter(is_sqr, range(1, 101))
2017-08-03
print map(lambda s:s.capitalize(), ['adam', 'LISA', 'barT'])
2017-08-02
def count():
fs = []
for i in range(1, 4):
def f(i=i):
return i*i
fs.append(f)
return fs
print count()[0]() ,count()[1]() ,count()[2]()
fs = []
for i in range(1, 4):
def f(i=i):
return i*i
fs.append(f)
return fs
print count()[0]() ,count()[1]() ,count()[2]()
2017-08-02
def calc_prod(lst):
def lazy_prod():
def f(x,y):
return x*y
return reduce(f,lst,1)
return lazy_prod
print calc_prod([1, 2, 3, 4])()
def lazy_prod():
def f(x,y):
return x*y
return reduce(f,lst,1)
return lazy_prod
print calc_prod([1, 2, 3, 4])()
2017-08-02
class Person(object):
def __init__(self,name,gender,birth,**kw):
self.name=name
self.gender=gender
self.birth=birth
self.__dict__.update(**kw)
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
print xiaoming.job
def __init__(self,name,gender,birth,**kw):
self.name=name
self.gender=gender
self.birth=birth
self.__dict__.update(**kw)
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
print xiaoming.job
2017-08-02