随笔分类 - Python
摘要:# 老虎 羊 喂养 import random # 父类 class Animal(): # 属性 def __init__(self,animal,w,call,food,room_num): self._animal=animal self._w=w self._call=call self._
阅读全文
摘要:# 羊 老虎 import random # 动物 class Animal(): def __init__(self,animal,weight,call,food,room_num): self._animal = animal self._weight = weight self._call
阅读全文
摘要:# 求1到这个数阶乘 #1*2*3*4=24 def fac(num): result=1 for i in range(1,num+1): result *= i return result mul=fac(4) print(f'阶乘结果:{mul}')
阅读全文
摘要:# 求10以内的质数 只能被自己和本身整除 # 2除以1是2 余数是0 # 2除以2是1 余数是0 # 4不是质数 因为4/2等于2 能被2整除 # 9不是质数 9%3 ==0 能被3整除 list_ob=[1,] for num in range(2,10): flag = True # 是质数吗
阅读全文
摘要:import allure import pytest import os @allure.epic('微信')# Epic(史诗)是指一个大型的任务 @allure.feature('首页') #feature通常包括详细的功能描述、特定的输入和预期的输出 @allure.story('登录')
阅读全文
摘要:import pytest @pytest.mark.parametrize('a,b,sum',[ # 参数化出来3组数据 (1,2,3), (2,3,5), (3,-19,-16) ]) def test_add(a,b,sum): assert a+b==sum # 如果 名称等于main 输
阅读全文
摘要:import pytest @pytest.mark.parametrize('a,b,sum',[ # 参数化出来3组数据 (1,2,3), (2,3,5), (3,-19,-16) ]) def test_add(a,b,sum): assert a+b==sum # 如果 名称等于main 输
阅读全文
摘要:#test_demo.pyimport allureimport pytestclass TestDemo: @allure.feature('比较功能') @allure.story('1等于1') def test_compare_numbers(self): expected = 1 actu
阅读全文
摘要:在pycharm中下载 allure-pytest包 解决办法: pip install allure-pytest 坑: 解释报错原因:使用的命令不对 pip install allure 报错 没有这个allure包
阅读全文
摘要:dict10={'a':'aa','b':'bb','c':'cc'} new_dict={'a':'a','b':'b'} dict10.update(new_dict)# updata 可以新增或者修改字典 print(dict10) ''' {'a': 'a', 'b': 'b', 'c':
阅读全文
摘要:import pytest class Test1: def test1(self): assert 1 == 1 assert 2 + 2 == 4 assert 3 + 3 == 6 if __name__=='__main__': pytest.main([__file__]) ''' tes
阅读全文
摘要:# 导入随机数包 import random # 第一个类 动物类 class Animal: # 定义属性 def __init__(self,animal,weight,call,food): self._animal=animal self._weight=weight self._call=
阅读全文
摘要:import random # 动物类 class Animal: def __init__(self, animal_type, weight, cries, food): self._animal_type = animal_type self._weight = weight self._cr
阅读全文
摘要:import random# 动物类class Animal: def __init__(self, animal_type, weight, cries, food): self._animal_type = animal_type self._weight = weight self._crie
阅读全文
摘要:# 目标获取10个房间里的动物 和体重 import random class Room: def __init__(self,roomnum,animal_type): # 房间号 self._roomnum=roomnum # 动物 self._animal_type=animal_type #
阅读全文
摘要:from loguru import logger logger.debug("异常") logger.info("异常") logger.warning("异常") logger.error("异常") logger.critical("异常") # 对日志做配置 放在指定的文件夹 当超过200K
阅读全文
摘要:try: # num=int(input("请输入数字:")) # print(1/num) age= int(input("请输入年龄,不要小于18岁:")) if age < 18: # 非python的异常,业务逻辑上的异常,主动异常 raise raise NameError('异常,年纪小
阅读全文
摘要:# 单例 司机只有一个 class Driver: _self=None _name = "Driver Jack" # 司机的姓名 _num = 0 # 司机的业绩 初始值是0 def __new__(cls, *args, **kwargs): if cls._self is None: cls
阅读全文
摘要:# 定义一个不重复的列表 import random list= [] count= 0 # 成功放入的次数 while count<5: num= random.randint(1,10) if num not in list: list.append(num) count+=1 # 成功后计数一
阅读全文
摘要:# 售票员卖票 class Driver: _self=None _name= 'Driver_Jack'# 售票员的名字 _num= 0 # 售票员的业绩 def __new__(cls, *args, **kwargs): if cls._self is None :# 如果售票员这个类是空 c
阅读全文
浙公网安备 33010602011771号