@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
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