Python入门题032类和函数级静态变量
题目:
实现类和函数级的静态变量。
视频教程:
Python入门题032:类和函数级静态变量
代码1:classPeople:Type人definit(self,name):self。namenamedefshow(self):print(f{self。name}是{self。Type})classTeacher(People):passclassStudent(People):passteacherliTeacher(李老师)studentmingStudent(小明)studenthongStudent(小红)print(1)teacherli。show()studentming。show()studenthong。show()print(2)People。Type僵尸teacherli。show()studentming。show()studenthong。show()print(3)People。Type人Student。Type僵尸teacherli。show()studentming。show()studenthong。show()print(4)People。Type人teacherli。show()studentming。show()studenthong。show()
代码2:defticktock():ifnothasattr(ticktock,counter):ticktock。counter0print(f欢迎光临,这是你第{ticktock。counter}次来了!)ticktock。counter1ticktock()ticktock()ticktock()