class BStudent(BasketballMixin,Student):
pass
class FTeacher(FootballMixin,Teacher):
pass
pass
class FTeacher(FootballMixin,Teacher):
pass
2018-12-30
import json
class Students(object):
def read(self):
return '["Tim", "Bob", "Alice"]'
s = Students()
print json.load(s)
class Students(object):
def read(self):
return '["Tim", "Bob", "Alice"]'
s = Students()
print json.load(s)
2018-12-30
print isinstance(t,Person)
print isinstance(t,Student)
print isinstance(t,Teacher)
print isinstance(t,object)
print isinstance(t,Student)
print isinstance(t,Teacher)
print isinstance(t,object)
2018-12-30
class Person(object):
def __init__(self, name, gender):
self.name = name
self.gender = gender
class Teacher(Person):
def __init__(self, name, gender, course):
super(Teacher,self).__init__(name,gender)
self.course = course
def __init__(self, name, gender):
self.name = name
self.gender = gender
class Teacher(Person):
def __init__(self, name, gender, course):
super(Teacher,self).__init__(name,gender)
self.course = course
2018-12-30
class Person(object):
__count = 0
@classmethod
def how_many(cls):
return cls.__count
def __init__(self,name):
self.name = name
Person.__count+=1
print Person.how_many()
p1 = Person('Bob')
print Person.how_many()
__count = 0
@classmethod
def how_many(cls):
return cls.__count
def __init__(self,name):
self.name = name
Person.__count+=1
print Person.how_many()
p1 = Person('Bob')
print Person.how_many()
2018-12-29
# -*- coding: UTF-8 -*-
###
def __init__(self, name, score):
self.name = name
self.__score = score
def get_grade(self):
if self.__score>=90:
return 'A-优秀'
elif self.__score>=60:
return 'B-及格'
else:
return 'C-不及格'
###
def __init__(self, name, score):
self.name = name
self.__score = score
def get_grade(self):
if self.__score>=90:
return 'A-优秀'
elif self.__score>=60:
return 'B-及格'
else:
return 'C-不及格'
2018-12-29
class Person(object):
__count = 0
def __init__(self, name):
self.name = name
Person.__count += 1
print Person.__count
p1 = Person('Bob')
p2 = Person('Alice')
try:
print Person.__count
except AttributeError:
print 'attributeerror'
__count = 0
def __init__(self, name):
self.name = name
Person.__count += 1
print Person.__count
p1 = Person('Bob')
p2 = Person('Alice')
try:
print Person.__count
except AttributeError:
print 'attributeerror'
2018-12-29
class Person(object):
count = 0
def __init__(self,name):
self.name = name
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+=1
p1 = Person('Bob')
print Person.count
p2 = Person('Alice')
print Person.count
p3 = Person('Tim')
print Person.count
2018-12-29
class Person(object):
def __init__(self, name, score):
self.name = name
self.__score = score
p = Person('Bob', 59)
print p.name
try:
print p.__score
except AttributeError:
print 'attribute error'
def __init__(self, name, score):
self.name = name
self.__score = score
p = Person('Bob', 59)
print p.name
try:
print p.__score
except AttributeError:
print 'attribute error'
2018-12-29
class Person(object):
def __init__(self,name,gender,birth,**kw):
self.name=name
self.gender =gender
self.birth=birth
for k,v in kw.items():
setattr(self,k,v)
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
def __init__(self,name,gender,birth,**kw):
self.name=name
self.gender =gender
self.birth=birth
for k,v in kw.items():
setattr(self,k,v)
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
2018-12-29
class Person(object):
pass
p1 = Person()
p1.name = 'Bart'
p2 = Person()
p2.name = 'Adam'
p3 = Person()
p3.name = 'Lisa'
L1 = [p1, p2, p3]
L2 = sorted(L1,lambda a, b: cmp(a.name, b.name))
print(L2[0].name)
print(L2[1].name)
print(L2[2].name)
pass
p1 = Person()
p1.name = 'Bart'
p2 = Person()
p2.name = 'Adam'
p3 = Person()
p3.name = 'Lisa'
L1 = [p1, p2, p3]
L2 = sorted(L1,lambda a, b: cmp(a.name, b.name))
print(L2[0].name)
print(L2[1].name)
print(L2[2].name)
2018-12-29
class Person:
pass
xiaoming = Person()
xiaohong = Person()
print xiaoming
print xiaohong
print xiaoming == xiaohong
pass
xiaoming = Person()
xiaohong = Person()
print xiaoming
print xiaohong
print xiaoming == xiaohong
2018-12-29
from __future__ import unicode_literals
s = 'am I an unicode?'
print isinstance(s, unicode)
s = 'am I an unicode?'
print isinstance(s, unicode)
2018-12-29
try:
import json
except ImportError:
from simplejson import json
print json.dumps({'python':2.7})
import json
except ImportError:
from simplejson import json
print json.dumps({'python':2.7})
2018-12-29
from os.path import isdir,isfile
print not isdir(r'/data/webroot/resource/python')
print not isfile(r'/data/webroot/resource/python/test.txt')
print not isdir(r'/data/webroot/resource/python')
print not isfile(r'/data/webroot/resource/python/test.txt')
2018-12-29