'''编程的两大思想:面对过程和面向对象'''
'''类与对象'''
'''创建类'''
class Student:
pass
print(type(Student))
print(id(Student))
print(Student)
class Student:
native_place='吉林'
def __init__(self,name,age):
self.name=name
self.age=age
def eat(self):
print('学生在吃饭')
@staticmethod
def method():
print('我使用了staticmethod进行修饰,所以我是静态方法')
@classmethod
def cm(cls):
print('我使用了classmethod进行修饰,所以我是类方法')
def drink():
print('喝水')
class Student:
native_place='吉林'
def __init__(self,name,age):
self.name=name
self.age=age
def eat(self):
print('学生在吃饭')
@staticmethod
def method():
print('我使用了staticmethod进行修饰,所以我是静态方法')
@classmethod
def cm(cls):
print('我使用了classmethod进行修饰,所以我是类方法')
def drink():
print('喝水')
stu1=Student('张三',20)
print(id(stu1))
print(type(stu1))
print(stu1)
print('---------------')
print(id(Student))
print(type(Student))
print(Student)
class Student:
native_place='吉林'
def __init__(self,name,age):
self.name=name
self.age=age
def eat(self):
print('学生在吃饭')
@staticmethod
def method():
print('我使用了staticmethod进行修饰,所以我是静态方法')
@classmethod
def cm(cls):
print('我使用了classmethod进行修饰,所以我是类方法')
def drink():
print('喝水')
stu1=Student('张三',20)
stu1.eat()
print(stu1.name)
print(stu1.age)
print('----------')
Student.eat(stu1)
class Student:
native_place='吉林'
def __init__(self,name,age):
self.name=name
self.age=age
def eat(self):
print('学生在吃饭')
@staticmethod
def method():
print('我使用了staticmethod进行修饰,所以我是静态方法')
@classmethod
def cm(cls):
print('我使用了classmethod进行修饰,所以我是类方法')
def drink():
print('喝水')
print(Student.native_place)
stu1=Student('张三',20)
stu2=Student('李四',22)
print(stu1.native_place)
print(stu2.native_place)
Student.native_place='天津'
print(stu1.native_place)
print(stu2.native_place)
print('----类方法的使用方式------')
Student.cm()
print('----静态方法的使用方式------')
Student.method()
class Student:
def __init__(self,name,age):
self.name=name
self.age=age
def eat(self):
print(self.name+'在吃饭')
stu1=Student('张三',20)
stu2=Student('李四',24)
print(id(stu1))
print(id(stu2))
print('-------为stu2动态的去绑定性别属性------')
stu2.gender='女'
print(stu1.name,stu1.age)
print(stu2.name,stu2.age,stu2.gender)
print('-------------')
stu1.eat()
stu2.eat()
def show():
print('定义在类之外的,称函数')
stu1.show=show()
stu1.show