python-类

class BoyFriend:
# 类属性
height = 175
weight = 120
money = "500万"

def __init__(self, name, age):
self.name = name
self.age = age

# 类函数
def cooking(self, food):
print(self.name, "会做饭",food)

def earn(self, type):
print(self.name, "月薪3万",type)

@classmethod
def sing(cls):
print("sing a song")

@staticmethod
def dance():
print("dancing dancing")

# 实例/对象 具体的一个例子 类名()
bf = BoyFriend('haha', 18)
print(bf.height)
bf.cooking('菜')
BoyFriend.cooking(bf,'面')
BoyFriend.sing()
BoyFriend.dance()
posted @ 2022-03-28 19:09  狒狒桑  阅读(25)  评论(0)    收藏  举报