python 局部变量和全局变量使用 2021-11-05

python 局部变量和全局变量使用

a = 666

def modify_a():
global a
a = 20

def print_a():
print("此时全局变量a的值:。,a)

modif_a()
print_a()

继承: 单继承 , 多继承

class person():
def init(self,name,age):
self.Name = name
self.Age = age

         def eat(self):
               print(" eat eat, fat, fat")
          def sleep(self):
                print("sleep")

class Teacher(Person):
def init(self,name,age,salary):
self.salary = salary
Person.init(self,name,age)

            def teach(self)
                  print("teach for the student")

t = Teacher(" zhangshan,25,1000000")

多继承 狗类--> 动物类-->生物类

class creature(object):
def init(self, age):
print("creat function")
self.age = age
def breath(self):
print(" most animals could breath")

class Animal(Creature):
def__init__(self,name,age):
print("Animal 构造方法")
self.name = name
Creature.init(self,age)
def eat(self):
print("eat rice")
class Dog(Animals):
def__init__(self,name,age,color):
print("Dog构造方法")
self.color = color
super().init(name,age)

d = Dog("旺财",是,'黄色')
print(d.name,d.age,d.color )

你可能感兴趣的:(python 局部变量和全局变量使用 2021-11-05)