面向对象
"""
面向对象:
    核心是对象二字,
        1.程序里面
            对象就是盛放数据属性和功能的容器,
           2. 现实中
              对象就是特征与技能的结合体
    Linux:一切皆文件
优点:扩展性强
缺点:编程复杂度高
应用场景:对扩展性要求较高的场景,比如:qq, 微信
    案例:
       西天取经
        学生选课系统
"""
类的概念
"""
对象:特征和节能的结合体
类:一系列对象相似的特征和相似的技能的结合体
强调:站在不同的角度,划分的分类是不一样的
问题:先有类还是先有对象?
    1.现实中:
        必须先有对象,在有类
    2. 程序中:
        必须先定义类,在调用类产生对象
"""
# 定义类
"""
class 类名():
    pass
    
    
def 函数名():
    pass
    
类名: 一般是首字母大写
"""
class Student():
    school = 'SH'
    
    def choose_course(self,course):
        self.courses.append(course)
        print("%s 选课成功 %s" % (self.name, self.courses))
        
# 类的名称空间
print(Student.__dict__)
print(Student.__dict__)
#
#
# # 造对象,调用类,产生对象
stu1 = Student()  # 调用类 产生空对象
# stu2 = Student()
#
print(stu1.__dict__)
调用类的过程就是实例化, 得到的对象就是一个实例
定制对象自己独有的属性
"""
    产生对象发生了几件事?
        1. 产生一个空对象,并且把该空对象当成第一个参数传递
"""
class Student():
    school = 'SH'
    # 初始化方法
    def __init__(stu_obj, name, age, gender, courses=[]):
        stu_obj.name = name  # stu1.__dict__['name'] = 'egon'
        stu_obj.age = age  # stu1.__dict__['age'] = 20
        stu_obj.gender = gender  # stu1.__dict__['gender'] = 'male'
        stu_obj.courses = courses  # stu1.__dict__['courses'] = []
    def choose_course(stu_dic, course):
        stu_dic['courses'].append(course)
        print("%s 选课成功 %s" % (stu_dic['name'], stu_dic['courses']))
        
 
# 类的名称空间
# print(Student.__dict__)
stu1 = Student('egon', 18 ,'male')
print(stu1.__dict__)
# stu2 = Student()
# stu1.name = 'egon'      # stu1.__dict__['name'] = 'egon'
# stu1.age = 18           # stu1.__dict__['age'] = 20
# stu1.gender = 'male'    # stu1.__dict__['gender'] = 'male'
# stu1.courses = []       # stu1.__dict__['courses'] = []
#
#
# stu2.name = 'tom'      # stu2.__dict__['name'] = 'egon'
# stu2.age = 18           # stu2.__dict__['age'] = 20
# stu2.gender = 'male'    # stu2.__dict__['gender'] = 'male'
# stu2.courses = []       # stu2.__dict__['courses'] = []
#
# init(stu1, 'egon', 18, 'male')
# init(stu2, 'tom', 18, 'male')
#
#
# print(stu1.__dict__)
# print(stu2.__dict__)       
        
属性查找
class Student():
    school = 'SH'
    # 初始化方法
    def __init__(stu_obj, name, age, gender, courses=[]):
        stu_obj.name = name  # stu1.__dict__['name'] = 'egon'
        stu_obj.age = age  # stu1.__dict__['age'] = 20
        stu_obj.gender = gender  # stu1.__dict__['gender'] = 'male'
        stu_obj.courses = courses  # stu1.__dict__['courses'] = []
    def choose_course(self, course):
        self.courses.append(course)
        print("%s 选课成功 %s" % (self.name, self.courses))
    # print(123)
# 类的名称空间
# print(Student.__dict__)
stu1 = Student('egon', 18 ,'male')
stu2 = Student('tom', 18 ,'male')
# print(stu1.__dict__)
# 1 类的属性查找
# print(Student.__dict__['school'])
# # Student.__dict__['xxx'] = 'xxx'
# del Student.__dict__['xxx']
# Student.xxx = 'xxx'
#
# del  Student.xxx
# Student.school = 'MMM'
# print(Student.school)
# print(Student.choose_course)
# Student.choose_course(stu1, 'python')
# 对象操作属性  点语法取值,先从自己对象中取,如果没有,在取类中取值
# print(stu1.school)
#
# stu1.xxx = 'x'
# del  stu1.xxx
# stu1.school = 'y'
# Student.school = 'x'
# print(stu1.school)
# 类中的属性是共享给所有对象的,但是,类中的方法是给对象用的, 并且,把对象自己当成第一个参数传递
# stu1.school = 'y'
# print(stu1.school)
#
# print(stu2.school)
stu1.choose_course('python')