print('hello,world')
def printName(isChinese,name,fName):
def innerPrint(a,b):
print('{0}{1}'.format(a,b))
if isChinese:
innerPrint(fName,name)
else:
innerPrint(name,fName)
printName(True,'chao','wang')
printName(False,'li','hua')
def outer():
b=20
def inner():
nonlocal b
print('inner b:',b)
b=60
inner()
print('outer b',b)
outer()
class Student:
def __init__(self,name,age):
self.name=name
self.age=age
def say_age(self):
print('{0}的年龄是{1}'.format(self.name,self.age))
Student('yang',18).say_age()
s1=Student('yang',18)
s1.score=100
s1.salary=1000
print(dir(s1))
print(isinstance(s1,Student))
stu2=Student
s1.say_age()
s2=stu2('yang',20)
s2.say_age()
class Student:
school='bupt'
count=0
def __init__(self,name,score):
self.name=name
self.score=score
Student.count=Student.count+1
def say_score(self):
print('我们的学校是:',Student.school)
print(self.name,'的分数是:',self.score)
f1=Student('yang',100)
f2=Student('wang',80)
f2.say_score()
f1.say_score()
print('一共创建了{0}个学生对象'.format(Student.count))
class Student:
school='bupt'
@classmethod
def printSchool(cls):
print(cls.school)
Student.printSchool()
class person:
def __del__(self):
print('销毁对象{0}'.format(self))
p1=person()
p2=person()
del p2
print('程序结束')
class salaryAccount:
def __call__(self,salary):
print('算工资了')
yearsalary=salary*12
daysalary=salary//22
hoursalary=daysalary//8
return dict(yearsalary=yearsalary,monthsalary=salary,daysalary=daysalary,hoursalary=hoursalary)
s=salaryAccount()
print(s(9000))