一、什么是类?
二、类的声明
class login:
class Dalao: name=‘寻找中‘ salary=‘18k‘ def auto_api_test(self):#self是类函数中默认的参数 print(‘大佬会接口测试‘) def auto_web_test(self): print(‘大佬会web自动化测试‘) def auto_app_test(self): print("大佬会APP自动化测试") dl=Dalao()#创建实例,类名+括号,即类里面函数的调用 print(‘大佬的名字是{0}‘.format(dl.name))#格式化输出 print(‘大佬的工资是{0}‘.format(dl.salary)) dl.auto_api_test() dl.auto_app_test() dl.auto_web_test()
class Dalao: def __init__(self,name,work_year,salary):#初始化函数 self.name=name self.work_year=work_year self.salary=salary def auto_api_test(self):#self是类函数中默认的参数 print(‘大佬会接口测试‘) def auto_web_test(self): print(‘大佬会web自动化测试‘) def auto_app_test(self): print("大佬会APP自动化测试") dl=Dalao(‘幸运号‘,‘5‘,‘18k‘)#创建实例,类名+括号,即类里面函数的调用 print(‘大佬的名字是{0}‘.format(dl.name))#格式化输出 print(‘大佬的工资是{0}‘.format(dl.salary)) dl.auto_api_test() dl.auto_app_test() dl.auto_web_test()
原文:https://www.cnblogs.com/jingdenghuakai/p/11788836.html