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
try:
import json
except ImportError:
from simplejson import json
#imoprt simplejson as json
print json.dumps({'python':2.7})
import json
except ImportError:
from simplejson import json
#imoprt simplejson as json
print json.dumps({'python':2.7})
2015-05-23
import os
print os.path.isdir(r'/data/webroot/resource/python')
print os.path.isfile(r'/data/webroot/resource/python/test.txt')
print os.path.isdir(r'/data/webroot/resource/python')
print os.path.isfile(r'/data/webroot/resource/python/test.txt')
2015-05-23
def count():
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(f())
return fs
f1, f2, f3 = count()
print f1, f2, f3
fs = []
for i in range(1, 4):
def f():
return i*i
fs.append(f())
return fs
f1, f2, f3 = count()
print f1, f2, f3
2015-05-23
请给 Person 类增加一个私有属性 __score,表示分数,再增加一个实例方法 get_grade(),能根据 __score 的值分别返回 A-优秀, B-及格, C-不及格三档。
应该是增加私用实例属性吧
应该是增加私用实例属性吧
2015-05-22
class Fib(object):
data = [0,1,1,2,3,5,8]
def __init__(self, num):
self.num = num
while( len(Fib.data) < num):
Fib.data.append(sum(Fib.data[-2:]))
def __len__(self):
return self.num
def __str__(self):
return str(Fib.data[:self.num])
data = [0,1,1,2,3,5,8]
def __init__(self, num):
self.num = num
while( len(Fib.data) < num):
Fib.data.append(sum(Fib.data[-2:]))
def __len__(self):
return self.num
def __str__(self):
return str(Fib.data[:self.num])
2015-05-21