def format_name(s):
return s.lower().capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.lower().capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
2018-03-14
print(sorted(L,key=lambda Student:(-Student.score,Student.name)))
2018-03-13
#类方法调用类的私有变量
@classmethod
def how_many(cls):
return cls.__count
@classmethod
def how_many(cls):
return cls.__count
2018-03-13
import math
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
2018-03-12
import json
class Students(object):
def __init__(self):
pass
def read(self):
s=r'["Tim", "Bob", "Alice"]'
return s
s = Students()
print json.load(s)
class Students(object):
def __init__(self):
pass
def read(self):
s=r'["Tim", "Bob", "Alice"]'
return s
s = Students()
print json.load(s)
2018-03-12
# 希望一次返回3个函数,分别计算1x1,2x2,3x3:
def count():
fs = []
for i in range(1, 4):
def f(j):
def g():
return j*j
return g
r = f(i)
fs.append(r)
return fs
f1, f2, f3 = count()
print(f1(), f2(), f3())
def count():
fs = []
for i in range(1, 4):
def f(j):
def g():
return j*j
return g
r = f(i)
fs.append(r)
return fs
f1, f2, f3 = count()
print(f1(), f2(), f3())
2018-03-12
class Person(object):
count = 0
def __init__(self, name):
self.name = name
Person.count = 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 = Person.count +1
p1 = Person('Bob')
print Person.count
p2 = Person('Alice')
print Person.count
p3 = Person('Tim')
print Person.count
2018-03-12
import math
def is_sqr(x):
if math.sqrt(x)-int (math.sqrt(x))==0:
return x
print filter(is_sqr, range(1, 101))
def is_sqr(x):
if math.sqrt(x)-int (math.sqrt(x))==0:
return x
print filter(is_sqr, range(1, 101))
2018-03-12