'''设计类
类名:见名之意,首字母大写,其他遵循驼峰原则
属性:见名之意,其他遵循驼峰原则
行为(方法/功能):见名之意,其他遵循驼峰原则



类名:Wife
属性:sex age height weight faceValue
行为:做饭 洗衣服 拖地 揉肩 捶腿


类名:Husband
属性:sex age height weight faceValue
行为:吃饭 看电视 打游戏 被揉肩 被捶腿


类名:Car
属性: color type
行为:跑
'''


'''
创建类
类:一种数据类型,本身并不占内存空间,根所学过的number,string,boolean等类似。用类创建实例化对象(变量),对象占内存空间

格式:
class 类名(父类列表):
属性
行为

'''
# object:基类,超类,所有类的父类,一般没有合适的父类就写object
class Person(object):
#定义属性(定义变量)
name = ""
age = 0
height = 0
weight = 0

#定义方法(定义函数)
#注意:方法的参数必须以self当第一个参数
#self代表类的实例(某个对象)
def run(self):
print("run")
def eat(self, food):
print("eat" + food)

相关文章:

  • 2021-08-18
  • 2022-12-23
  • 2021-11-23
  • 2021-11-23
  • 2021-09-25
  • 2021-09-30
  • 2021-10-07
  • 2021-07-07
猜你喜欢
  • 2021-08-04
  • 2022-12-23
  • 2022-02-16
  • 2022-12-23
  • 2021-11-23
  • 2021-11-09
  • 2022-12-23
相关资源
相似解决方案