最赞回答 / 筱兵潇将
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。它基于JavaScript的一个子集。 JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族的习惯(包括C, C++, C#, Java, JavaScript, Perl, Python等)。这些特性使JSON成为理想的数据交换语言。易于人阅读和编写,同时也易于机器解析和生成。编码:把一个Python对象编码转换成Json字符串 json.dumps()解码:把Json格式字符串解码转换成Py...
2015-05-27
def calc_prod(lst):
def chenji(x,y):
return x*y
def chen():
return reduce(chenji,lst)
return chen
f = calc_prod([1, 2, 3, 4])
print f() 哈哈哈哈 竟然让我写出来了
def chenji(x,y):
return x*y
def chen():
return reduce(chenji,lst)
return chen
f = calc_prod([1, 2, 3, 4])
print f() 哈哈哈哈 竟然让我写出来了
2015-05-27
最赞回答 / 星际怪物
class Person(object): __count = 0 def __init__(self, name): Person.__count=Person.__count+1 self.name =name print Person.__countp1 = Person('Bob') #1p2 = Person('Alice') #2Person.__count=5 print Person.__count #5p3 = Person('...
2015-05-27
import math
def is_sqr(x):
return (math.sqrt(x)) in range(1,101)
print filter(is_sqr, range(1,101))
#我这个写法简直投机取巧...
def is_sqr(x):
return (math.sqrt(x)) in range(1,101)
print filter(is_sqr, range(1,101))
#我这个写法简直投机取巧...
2015-05-26
发现不能在类的初始化函数中定义通过'self.attr'来控制类属性而应该用‘类名.attr’来操作类属性
2015-05-26
self.name=name
self.gender=gender
for k,v in kw.iteritems():
setattr(self,k,v)
self.gender=gender
for k,v in kw.iteritems():
setattr(self,k,v)
2015-05-25
class Fib(object):
def __init__(self):
pass
def __call__(self, num):
f = [0, 1]
for i in range(num-2):
f.append(f[i] + f[i+1])
return f
f = Fib()
print f(10)
def __init__(self):
pass
def __call__(self, num):
f = [0, 1]
for i in range(num-2):
f.append(f[i] + f[i+1])
return f
f = Fib()
print f(10)
2015-05-24
@classmethod
def how_many(cls):
return cls.__count
def __init__(self,name):
self.name=name
Person.__count=Person.__count+1
def how_many(cls):
return cls.__count
def __init__(self,name):
self.name=name
Person.__count=Person.__count+1
2015-05-24
def __init__(self, name, score):
self.name=name
self.__score=score
def get_grade(self):
if self.__score>=80:
return 'A'
else:
if self.__score>=60:
return 'B'
else:
return 'C'
self.name=name
self.__score=score
def get_grade(self):
if self.__score>=80:
return 'A'
else:
if self.__score>=60:
return 'B'
else:
return 'C'
2015-05-24
count=0
def __init__(self,name):
self.name=name
Person.count=Person.count+1
def __init__(self,name):
self.name=name
Person.count=Person.count+1
2015-05-24
class Person(object):
pass
xiaoming = Person()
xiaohong = Person()
print xiaoming
print xiaohong
print xiaoming==xiaohong
pass
xiaoming = Person()
xiaohong = Person()
print xiaoming
print xiaohong
print xiaoming==xiaohong
2015-05-23