类与对象
Python 类的语法 关键字class def函数名(参数):函数关键字
class 类名:#类名的规范是数字字母下划线 不能以数字开头 首字母大写 驼峰命名
类属性
类方法
class BoyFriend:
# 类属性:
height=175
weight=130
money=“500万”
# 类函数 类方法
def print_msg(self): #固定的占坑符合 类里边的方法 都必须带self这个参数
print(self)
def cooking(self):#会做饭
print("男朋友要回做饭!")
def earn(self):#会挣钱
print("男朋友月薪3万")
实例/对象 具体的一个例子 类名()
bf=BoyFriend()
print(bf)
print("*"*20)
bf.print_msg()
print(bf.money)
实例 具有类里面的所有属性和方法的使用权限
调用属性 实例:属性名
调用方法/函数:实例.方法名() 实例.函数名()def开头的才是函数
#作业:写一个软件测试工程师类,要求有属性有函数,并完成属性和函数的调用
class Tester:
name=‘小明’
sex=‘女’
def working(self):
print('我会测试')
test=Tester()
print(test)
print(test.name)