标签:arm soft att 类方法 object sel 动作 phone san
# _*_ coding:utf-8 _*_
# @Time :2020/1/14 22:24
# @Author :dery
# @File :object_attribute.py
# @Software :PyCharm
class Student: # 定义类
# 类属性
name = ‘dery‘
age = ‘2‘
# 使用类创建对象:对象 = 类名()
dery = Student()
print(dery.name)
dery.age = 32 # 动态创建对象属性 赋值操作 对象属性
print(dery.age) # 先找自己空间的属性,再去类空间找对应属性
yupeng = Student()
yupeng.name = ‘xiaoyupeng‘
print(yupeng.name)
yupeng.age = 1
print(yupeng.age)
Student.name = ‘zhangsan‘
ruirui = Student()
print(ruirui.name)
# _*_ coding:utf-8 _*_
# @Time :2020/1/14 22:51
# @Author :dery
# @File :object_method.py
# @Software :PyCharm
# 类中的方法:动作
# 种类:普通方法、类方法、静态方法、魔术方法
class Phone:
brand = ‘xiaomi‘
price = 4999
type = ‘mate 802‘
note = ‘‘
def call(self): # 类里面的方法:call
print(self)
print(‘打电话‘)
print(‘留言:‘, self.note)
phone1 = Phone()
phone1.note = ‘我是phone1的note‘
print(phone1, ‘----------1-------‘)
# print(phone1.type)
phone1.call()
print(‘*‘ * 30)
phone2 = Phone()
print(phone2, ‘--------2-----‘)
phone2.call()
标签:arm soft att 类方法 object sel 动作 phone san
原文地址:https://www.cnblogs.com/python-beginner/p/12194594.html