07 2023 档案

摘要:json.loads()函数只能将一个合法的JSON字符串转换为相应的Python对象(例如字典、列表等)。它无法处理包含多个JSON字符串的字符串 第一种str='{"code": 9999, "data": "", "flag": "11", "msg": "该用户不存在!", "success 阅读全文
posted @ 2023-07-30 18:33 胖豆芽 阅读(954) 评论(2) 推荐(0) 编辑
摘要:# py 文件必须test开头 # 测试类必须Test开头 import ast import pytest from utils.handle_yaml import get_yaml from utils.handle_xls_my import get_excel_data import js 阅读全文
posted @ 2023-07-30 15:18 胖豆芽 阅读(19) 评论(0) 推荐(0) 编辑
摘要:# 导包import xlrddef get_excel_data(file_path,sheet_name,case_name,*args): # 定义一个列表 存[(第下标1行里 test列里的值,test1列里的值),(第下标1行里 test列里的值,test1列里的值)] xls_data 阅读全文
posted @ 2023-07-28 14:10 胖豆芽 阅读(4) 评论(0) 推荐(0) 编辑
摘要:第一版 写死了 列的值的下标,不够 人性化 ,还需要去数列在第几个位置 # 导包 import xlrd # 第一步 根据包提供的方法 读某个路径下的xls workbook = xlrd.open_workbook('../data/testcase.xls') # 第二步 根据名字找某个表 每个 阅读全文
posted @ 2023-07-28 13:31 胖豆芽 阅读(3) 评论(0) 推荐(0) 编辑
摘要:# 导包 import xlrd # 第一步 根据包提供的方法 读某个路径下的xls workbook = xlrd.open_workbook('../data/testcase.xls') # 第二步 根据名字找某个表 每个excel里有Sheet1 Sheet2 等 worksheet = w 阅读全文
posted @ 2023-07-28 11:31 胖豆芽 阅读(132) 评论(0) 推荐(0) 编辑
摘要:# 羊 老虎 饲养员 import random # 基类 class Animal(): # 属性 def __init__(self,animal,w,call,food,room_num): self._animal=animal self._w=w self._call=call self. 阅读全文
posted @ 2023-07-27 11:40 胖豆芽 阅读(3) 评论(0) 推荐(0) 编辑
摘要:# 显示被谁调用了 # inspect 审查 检查 import inspect def bei(): # stack 堆叠 print(f'我被{inspect.stack()[1][3]}调用') def king(): print('我调用了bei') bei() bei() king() ' 阅读全文
posted @ 2023-07-27 11:00 胖豆芽 阅读(2) 评论(0) 推荐(0) 编辑
摘要:# 背景 # 计算机字节串(UTF-8 编码):b'\xe4\xbd\xa0\xe5\xa5\xbd' # 解码为人类语言字符串(Unicode 编码):'你好' # 第一部分 md5加密 # md5加密 对字节加密,返回的结果需要将字节转16进制字符串 # 导包 import hashlib de 阅读全文
posted @ 2023-07-26 12:20 胖豆芽 阅读(9) 评论(0) 推荐(0) 编辑
摘要:# md5加密 对字节加密,返回的结果需要将字节转16进制字符串 # 导包 import hashlib def get_md5(data,salt=' '): data = hashlib.md5(data.encode())# md5加密之前需要先将处理对象 转字节 # 处理之后需要将处理后的数 阅读全文
posted @ 2023-07-26 11:19 胖豆芽 阅读(5) 评论(0) 推荐(0) 编辑
摘要:在PyCharm中更改虚拟环境为系统环境的步骤如下: 打开PyCharm,点击顶部菜单栏的 "File"(文件)。 在弹出的下拉菜单中,选择 "Settings"(设置)。 在 "Settings" 窗口中,展开 "Project"(项目)下的 "Project Interpreter"(项目解释器 阅读全文
posted @ 2023-07-25 17:10 胖豆芽 阅读(559) 评论(0) 推荐(0) 编辑
摘要:pip install -i https://mirrors.aliyun.com/pypi/simple/ pycryptodome 阅读全文
posted @ 2023-07-25 16:54 胖豆芽 阅读(4) 评论(0) 推荐(0) 编辑
摘要:# md5 加盐 fqs import hashlib def get_md5_y(psw,salt): psw += salt obj_psw_md5 = hashlib.md5(psw.encode('utf-8')) obj_str = obj_psw_md5.hexdigest() prin 阅读全文
posted @ 2023-07-25 14:35 胖豆芽 阅读(11) 评论(0) 推荐(0) 编辑
摘要:import json # # 假设有一个 JSON 对象 # data = { # "name": "John", # "age": 30, # "city": "New York" # } # # # 将 JSON 对象转换为字符串 # json_str = json.dumps(data) # 阅读全文
posted @ 2023-07-25 11:58 胖豆芽 阅读(15) 评论(0) 推荐(0) 编辑
摘要:# 羊 老虎 饲养员 # 父类 import random class Animal(): # 属性 def __init__(self,animal,w,call,food,room_num): self._animal = animal self._w = w self._call = call 阅读全文
posted @ 2023-07-24 11:13 胖豆芽 阅读(3) 评论(0) 推荐(0) 编辑
摘要:# 老虎 羊 喂养 import random # 父类 class Animal(): # 属性 def __init__(self,animal,w,call,food,room_num): self._animal=animal self._w=w self._call=call self._ 阅读全文
posted @ 2023-07-23 21:22 胖豆芽 阅读(6) 评论(0) 推荐(0) 编辑
摘要:# 羊 老虎 import random # 动物 class Animal(): def __init__(self,animal,weight,call,food,room_num): self._animal = animal self._weight = weight self._call 阅读全文
posted @ 2023-07-22 22:03 胖豆芽 阅读(4) 评论(0) 推荐(0) 编辑
摘要:# 求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}') 阅读全文
posted @ 2023-07-21 16:34 胖豆芽 阅读(37) 评论(0) 推荐(0) 编辑
摘要:# 求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 # 是质数吗 阅读全文
posted @ 2023-07-21 14:19 胖豆芽 阅读(58) 评论(0) 推荐(0) 编辑
摘要:import allure import pytest import os @allure.epic('微信')# Epic(史诗)是指一个大型的任务 @allure.feature('首页') #feature通常包括详细的功能描述、特定的输入和预期的输出 @allure.story('登录') 阅读全文
posted @ 2023-07-21 13:33 胖豆芽 阅读(7) 评论(0) 推荐(0) 编辑
摘要: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 输 阅读全文
posted @ 2023-07-21 12:06 胖豆芽 阅读(7) 评论(0) 推荐(0) 编辑
摘要: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 输 阅读全文
posted @ 2023-07-21 12:03 胖豆芽 阅读(10) 评论(0) 推荐(0) 编辑
摘要:#test_demo.pyimport allureimport pytestclass TestDemo: @allure.feature('比较功能') @allure.story('1等于1') def test_compare_numbers(self): expected = 1 actu 阅读全文
posted @ 2023-07-20 19:24 胖豆芽 阅读(92) 评论(0) 推荐(0) 编辑
摘要:在pycharm中下载 allure-pytest包 解决办法: pip install allure-pytest 坑: 解释报错原因:使用的命令不对 pip install allure 报错 没有这个allure包 阅读全文
posted @ 2023-07-20 18:02 胖豆芽 阅读(256) 评论(0) 推荐(0) 编辑
摘要: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': 阅读全文
posted @ 2023-07-20 12:27 胖豆芽 阅读(6) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2023-07-19 21:55 胖豆芽 阅读(10) 评论(0) 推荐(0) 编辑
摘要:# 导入随机数包 import random # 第一个类 动物类 class Animal: # 定义属性 def __init__(self,animal,weight,call,food): self._animal=animal self._weight=weight self._call= 阅读全文
posted @ 2023-07-19 18:35 胖豆芽 阅读(2) 评论(0) 推荐(0) 编辑
摘要:import random # 动物类 class Animal: def __init__(self, animal_type, weight, cries, food): self._animal_type = animal_type self._weight = weight self._cr 阅读全文
posted @ 2023-07-18 22:11 胖豆芽 阅读(3) 评论(0) 推荐(0) 编辑
摘要:import random# 动物类class Animal: def __init__(self, animal_type, weight, cries, food): self._animal_type = animal_type self._weight = weight self._crie 阅读全文
posted @ 2023-07-18 17:59 胖豆芽 阅读(1) 评论(0) 推荐(0) 编辑
摘要:# 目标获取10个房间里的动物 和体重 import random class Room: def __init__(self,roomnum,animal_type): # 房间号 self._roomnum=roomnum # 动物 self._animal_type=animal_type # 阅读全文
posted @ 2023-07-17 21:48 胖豆芽 阅读(17) 评论(0) 推荐(0) 编辑
摘要:from loguru import logger logger.debug("异常") logger.info("异常") logger.warning("异常") logger.error("异常") logger.critical("异常") # 对日志做配置 放在指定的文件夹 当超过200K 阅读全文
posted @ 2023-07-17 21:47 胖豆芽 阅读(16) 评论(0) 推荐(0) 编辑
摘要:try: # num=int(input("请输入数字:")) # print(1/num) age= int(input("请输入年龄,不要小于18岁:")) if age < 18: # 非python的异常,业务逻辑上的异常,主动异常 raise raise NameError('异常,年纪小 阅读全文
posted @ 2023-07-17 19:25 胖豆芽 阅读(5) 评论(0) 推荐(0) 编辑
摘要:# 单例 司机只有一个 class Driver: _self=None _name = "Driver Jack" # 司机的姓名 _num = 0 # 司机的业绩 初始值是0 def __new__(cls, *args, **kwargs): if cls._self is None: cls 阅读全文
posted @ 2023-07-17 17:40 胖豆芽 阅读(5) 评论(0) 推荐(0) 编辑
摘要:# 定义一个不重复的列表 import random list= [] count= 0 # 成功放入的次数 while count<5: num= random.randint(1,10) if num not in list: list.append(num) count+=1 # 成功后计数一 阅读全文
posted @ 2023-07-17 17:12 胖豆芽 阅读(6) 评论(0) 推荐(0) 编辑
摘要:# 售票员卖票 class Driver: _self=None _name= 'Driver_Jack'# 售票员的名字 _num= 0 # 售票员的业绩 def __new__(cls, *args, **kwargs): if cls._self is None :# 如果售票员这个类是空 c 阅读全文
posted @ 2023-07-16 21:04 胖豆芽 阅读(2) 评论(0) 推荐(0) 编辑
摘要:# 单例 class Driver: _self=None def __new__(cls, *args, **kwargs): if cls._self is None: cls._self=super().__new__(cls) return cls._self def __init__(se 阅读全文
posted @ 2023-07-15 21:01 胖豆芽 阅读(13) 评论(0) 推荐(0) 编辑
摘要:理解单例前需要了解 init 和new 这是init的效果 # 认识new 和init class People(object): # def __new__(cls, *args, **kwargs): # print("执行了new") # return object.__new__(cls) 阅读全文
posted @ 2023-07-15 18:59 胖豆芽 阅读(2) 评论(0) 推荐(0) 编辑
摘要:import math class Circle: def __init__(self,r): self._r= r @property def area(self):#def >define 定义一个函数或方法 求面积 mianji=round(self._r**2*math.pi,2)# rou 阅读全文
posted @ 2023-07-15 15:26 胖豆芽 阅读(17) 评论(0) 推荐(0) 编辑
摘要:# 反射class Webb: def reg(self): print("欢迎进入注册页面") def login(self): print("欢迎进入登录页面") def home(self): print("欢迎进入主页") def about(self): print("欢迎进入关于页面") 阅读全文
posted @ 2023-07-15 14:09 胖豆芽 阅读(9) 评论(0) 推荐(0) 编辑
摘要:class MyClass: @classmethod def my_class_method(cls, arg1, arg2): # 使用cls参数访问类的属性和调用类的方法 print("This is a class method") print("Arguments:", arg1, arg 阅读全文
posted @ 2023-07-14 17:31 胖豆芽 阅读(29) 评论(0) 推荐(0) 编辑
摘要:继承的示例:class Animal(object):# 父类 def run(self): print('Animal is running...') class Dog(Animal): def run(self):# 狗类 继承了 动物类 print('Dog is running...') 阅读全文
posted @ 2023-07-14 16:58 胖豆芽 阅读(2) 评论(0) 推荐(0) 编辑
摘要:1 没有范围限制 在类外部可以更改类内部的属性值 # 但是,既然Student实例本身就拥有这些数据,要访问这些数据,就没有必要从外面的函数去访问, # 可以直接在Student类的内部定义访问数据的函数,这样,就把“数据”给封装起来了. # 这些封装数据的函数是和Student类本身是关联起来的, 阅读全文
posted @ 2023-07-14 16:23 胖豆芽 阅读(9) 评论(0) 推荐(0) 编辑
摘要:1. # 理解类 class Student(object): pass bart= Student() # 变量bart指向的就是一个Student的实例,后面的0x10a67a590是内存地址,每个object的地址都不一样,而Student本身则是一个类 # print(bart)# <__m 阅读全文
posted @ 2023-07-14 15:20 胖豆芽 阅读(6) 评论(0) 推荐(0) 编辑
摘要:# 冒泡 最大的在最后面 def maopao(arr): # 列表的长度-1=最大下标 index_max=len(arr)-1 # 外层循环 for i in range(index_max): # 内存循环比大小 flag=False # 默认不需要交换 for x in range(inde 阅读全文
posted @ 2023-07-13 21:42 胖豆芽 阅读(2) 评论(0) 推荐(0) 编辑
摘要:求aabb之间的值(正则取的是列表形式) import re str1 = 'aaggbbccddaaggbbccdd' new_str=re.findall(r'aa(.*?)bb',str1) print(new_str) ''' ['gg', 'gg'] ''' 阅读全文
posted @ 2023-07-13 21:03 胖豆芽 阅读(3) 评论(0) 推荐(0) 编辑
摘要:('2017-03-13 11:50:09',271,131), ('2017-03-14 16:52:19',273,131), ('2017-03-13 11:50:19',271,126), import re f_path='d:/1/qian.txt' dict1={} with open 阅读全文
posted @ 2023-07-13 13:38 胖豆芽 阅读(3) 评论(0) 推荐(0) 编辑
摘要:# 请实现一个程序,实现如下需求点: # 1.程序开始的时候提示用户输入学生年龄信息 格式如下:# Mike Mos,9;Jack Green ,21# 我们假设 用户输入 上面的信息,必定会遵守下面的规则:# 学生信息之间用分号隔开 (分号前后可能有不定数量的空格)# 每个学生信息里的 姓名和 年 阅读全文
posted @ 2023-07-10 20:07 胖豆芽 阅读(10) 评论(0) 推荐(0) 编辑
摘要:# 求各类文件大小的总和,并写到新的文件中 import re # 定义一个字典做文件类型的归类 dict_file={} with open('log.txt') as files,open('d:/1/new2.txt','w') as f: for file in files: # 获得字符串 阅读全文
posted @ 2023-07-10 19:29 胖豆芽 阅读(28) 评论(0) 推荐(0) 编辑
摘要:# 根据身份证判断 是男还是女 id_card='410991198812237025' # 第一步 获得倒数第二位的信息 并转为int类型 id=int(id_card[-2:-1]) # 第二步 判断偶数 女 if id%2 == 0: print("女") else: print("男") 阅读全文
posted @ 2023-07-10 18:58 胖豆芽 阅读(6) 评论(0) 推荐(0) 编辑
摘要:# 字典和json 格式 的对比p_dict={'name':'fqs','age':18}p_json='{"name":"fqs","age":18}'# 1 将字典转为json格式import jsonresult1=json.dumps(p_dict)print(result1,type(r 阅读全文
posted @ 2023-07-10 17:50 胖豆芽 阅读(20) 评论(0) 推荐(0) 编辑
摘要:# 对字典的遍历 d={'1':'aaa','name':'fqs','age':'18'} for i in d: print(i) ''' 1 name age ''' for key in d.keys(): print(key) ''' ''' 1 name age ''' ''' for 阅读全文
posted @ 2023-07-10 17:21 胖豆芽 阅读(6) 评论(0) 推荐(0) 编辑
摘要:d={1:'abc',3.2:'jj','pai':3.1415} # 更改和新增 d.update({1:'ABC',9:9}) print(d) ''' {1: 'ABC', 3.2: 'jj', 'pai': 3.1415, 9: 9} ''' d={1:'abc',3.2:'jj','pai 阅读全文
posted @ 2023-07-10 17:09 胖豆芽 阅读(4) 评论(0) 推荐(0) 编辑
摘要:file_path='D:/1/1.txt' with open(file_path) as file1: print(file1.read()) ''' ffqqss ''' file_path='D:/1/1.txt' # 1.read 返回字符串 with open(file_path) as 阅读全文
posted @ 2023-07-10 15:27 胖豆芽 阅读(6) 评论(0) 推荐(0) 编辑
摘要:# 求换行符的长度 name='fqs' chang='\t' print(len(chang)) # 演示换行符 print("Hello\nWorld") # 演示制表符 print("Name\tAge\tCity") print("John\t25\tNew York") print("Li 阅读全文
posted @ 2023-07-10 15:19 胖豆芽 阅读(12) 评论(0) 推荐(0) 编辑
摘要:# 格式化字符串 name='fqs' age=18 hobby='game' print(f'第一种name:{name:10},age:{age:10}') print('第二种name:{0:10},age:{1:10}'.format(name,age)) print('第三种name:{0 阅读全文
posted @ 2023-07-10 14:22 胖豆芽 阅读(16) 评论(0) 推荐(0) 编辑
摘要:# 99乘法表for i in range(1,10): for j in range(1,i+1): print(f'{j}*{i}={i*j}',end='\t')#制表符 使得更整齐 print(' ') 阅读全文
posted @ 2023-07-09 17:24 胖豆芽 阅读(8) 评论(0) 推荐(0) 编辑
摘要:print(1,2,3,end='')# 不换行,一行内 输出下一列的值 print(4) ''' 1 2 34 ''' 阅读全文
posted @ 2023-07-09 16:55 胖豆芽 阅读(5) 评论(0) 推荐(0) 编辑
摘要:phone1_3=int(phone1[:3]) if not phone1.isdigit(): print("非法输入") else: if len(phone1)!=11: print("非法输入") else: if phone1_3>=130 and phone1_3<=150: prin 阅读全文
posted @ 2023-07-09 16:16 胖豆芽 阅读(10) 评论(0) 推荐(0) 编辑
摘要:a=1 b=10 a,b=b,a print(a,b)#10 1 阅读全文
posted @ 2023-07-09 13:33 胖豆芽 阅读(6) 评论(0) 推荐(0) 编辑
摘要:l=sorted([36, 5, -12, 9, -21]) print(l) ''' [-21, -12, 5, 9, 36] ''' l=sorted([36, 5, -12, 9, -21],key=abs) print(l) ''' [5, 9, -12, -21, 36] ''' # 按照 阅读全文
posted @ 2023-07-08 21:45 胖豆芽 阅读(7) 评论(0) 推荐(0) 编辑
摘要:# 去掉空白的字符 def not_empty(s): return s and s.strip() l=list(filter(not_empty, ['A', '', 'B', None, 'C', ' '])) print(l) ''' ['A', 'B', 'C'] ''' 阅读全文
posted @ 2023-07-08 21:39 胖豆芽 阅读(6) 评论(0) 推荐(0) 编辑
摘要:# 求x的平方的列表 l = list(map(lambda x: x*x, [1, 2, 3, 4])) print(l)# [1, 4, 9, 16] names = ['adam', 'LISA', 'barT'] formatted_names = list(map(lambda x: x. 阅读全文
posted @ 2023-07-08 21:24 胖豆芽 阅读(26) 评论(0) 推荐(0) 编辑
摘要:# 自动生成 1 2 3 l=list(range(1,4)) print(l) #求 1*1 2*2 3*3 l2=[] for x in range(1,4): l2.append(x*x) print(l2) # 简化 print([x * x for x in range(1, 4)]) # 阅读全文
posted @ 2023-07-08 20:40 胖豆芽 阅读(9) 评论(0) 推荐(0) 编辑
摘要:# 字符串的for 循环 str1 = 'abc' for i in str1: print(i) ''' a b c ''' # 字典的for 循环 dict1 = {'name':'fqs','age':18,'address':'beijing'} for key in dict1: prin 阅读全文
posted @ 2023-07-08 19:54 胖豆芽 阅读(5) 评论(0) 推荐(0) 编辑
摘要:str1='abcd' stat省去0_num_end = str1[:2] print(stat省去0_num_end) stat_num_end省去結尾的下标 = str1[2:] print(stat_num_end省去結尾的下标) ''' ab cd ''' def trim(s): if 阅读全文
posted @ 2023-07-08 19:47 胖豆芽 阅读(21) 评论(0) 推荐(0) 编辑
摘要:def hanoi(n, source, target, auxiliary): if n > 0: # 将 n-1 个盘子从源柱子移动到辅助柱子 hanoi(n-1, source, auxiliary, target) # 将最大的盘子从源柱子移动到目标柱子 print("Move disk", 阅读全文
posted @ 2023-07-08 17:25 胖豆芽 阅读(5) 评论(0) 推荐(0) 编辑
摘要:from typing import Union my_list:list[Union[str,int]]=[1,2,"it",'it'] my_doc:dict[str,Union[str,int]]={'name':'周',"age":31} print(my_list,my_doc) 阅读全文
posted @ 2023-07-07 18:25 胖豆芽 阅读(3) 评论(0) 推荐(0) 编辑
摘要:class Phone: producer="IT" def call_by_5g(self): print("父类使用5g网络进行通话") # 定义子类 class MyPhone(Phone): producer = 'TO' def call_by_5g(self): print("自己的手机 阅读全文
posted @ 2023-07-06 21:50 胖豆芽 阅读(3) 评论(0) 推荐(0) 编辑
摘要:class Phone: IMEI=2020001 producer="apple" def call_by_4g(self): print("4g通话") class NFCReader: nfc_type="第五代" producer="apple" def read_card(self): p 阅读全文
posted @ 2023-07-06 21:18 胖豆芽 阅读(1) 评论(0) 推荐(0) 编辑
摘要:class Phone: IMEI=2020001 producer="apple" def call_by_4g(self): print("4g通话") class Phone2023(Phone): face_id="2233" def call_by_5g(self): print(f"20 阅读全文
posted @ 2023-07-06 20:55 胖豆芽 阅读(2) 评论(0) 推荐(0) 编辑
摘要:class Phone: __current_voltage=3 #当前手机运行的电压 def __keep_single_core(self):#让手机单核运行的方法 print("让CPU以单核模式运行") def call_by_5g(self):#定义一个共有的方法 调用私有的方法和属性 i 阅读全文
posted @ 2023-07-06 20:01 胖豆芽 阅读(9) 评论(0) 推荐(0) 编辑
摘要:class Student:#创建一个类 name=None age=None tel=None def __init__(self,name,age,tel):#构造函数 self.name=name self.age=age self.tel=tel print("student类创建了一个对象 阅读全文
posted @ 2023-07-06 17:07 胖豆芽 阅读(4) 评论(0) 推荐(0) 编辑
摘要:class student: name=None def say_hi(self,msg): print(f"大家好呀,我是:{self.name},{msg}") stu=student() stu.name='fqs' stu.say_hi("我想死大家了") #设计一个闹钟 class Clo 阅读全文
posted @ 2023-07-06 16:14 胖豆芽 阅读(2) 评论(0) 推荐(0) 编辑
摘要:student_info={ 15:{'jack','rose',}, 18:{'jj'}, 35:{'a','b','c','d'}, } age_counts = {}# 定义一个字典 key=age value=name的长度 for age in student_info: count = 阅读全文
posted @ 2023-07-05 21:51 胖豆芽 阅读(14) 评论(0) 推荐(0) 编辑
摘要:import os os.system('mspaint D:\\1\\1.png') print('after call') ''' 打开一个图片 关闭后输出 after call ''' 阅读全文
posted @ 2023-07-05 20:47 胖豆芽 阅读(3) 评论(0) 推荐(0) 编辑
摘要:try: b=4/0 except ZeroDivisionError: print("获取 ZeroDivisionError ") ''' 获取 ZeroDivisionError ''' try: b=4/0 except ZeroDivisionError as e:# 获取更详细的信息 p 阅读全文
posted @ 2023-07-05 20:11 胖豆芽 阅读(1) 评论(0) 推荐(0) 编辑
摘要:读相关fp=open('D:/1/1.txt') #获取前两个字符 str1=fp.read(2) print(str1) #获取前两个字符 str2=fp.read(2) print(str2) #获取前两个字符获取剩余的全部字符 str3=fp.read() print(str3) #打开后 关 阅读全文
posted @ 2023-07-05 18:07 胖豆芽 阅读(13) 评论(0) 推荐(0) 编辑
摘要:# 长度 数组的长度 len1=len([0,1,2,3,4]) print(len1) max1=max([0,1,2,3,4]) print(max1) min1=min([0,1,2,3,4]) print(min1) # 长度 元祖的长度 len1=len((0,1,2,3,4)) prin 阅读全文
posted @ 2023-07-05 16:46 胖豆芽 阅读(1) 评论(0) 推荐(0) 编辑
摘要:def fun(name,age,**kwargs): return kwargs print(fun('fqs','18',address="beijing",school='xy')) ''' {'address': 'beijing', 'school': 'xy'} ''' # 函数 不确定 阅读全文
posted @ 2023-07-05 16:02 胖豆芽 阅读(9) 评论(0) 推荐(0) 编辑
摘要:# 函数 在函数里设置全局变量,会因为被赋值而修改 x=2 def funcx(): global x #这个x 是全局变量 会因为函数里面被赋值而修改 x=9 print("this x is in the funcx:-->",x) funcx() print(" ") print("this 阅读全文
posted @ 2023-07-05 12:23 胖豆芽 阅读(4) 评论(0) 推荐(0) 编辑
摘要:# 函数 传参 def foo1(name,address): print(name,address) # 直接传入参数 foo1('fqs',"huilongguan") # 关键字传入参数 foo1(name='doudou',address='huilongguan') ''' fqs hui 阅读全文
posted @ 2023-07-05 11:19 胖豆芽 阅读(1) 评论(0) 推荐(0) 编辑
摘要:# continue 仅终止内循环 放遇到Lucy时 跳过;继续下个循环boys=['mike','jack','tom']girls=['lily','lucy','mary']for boy in boys: for girl in girls: if girl == 'lucy': conti 阅读全文
posted @ 2023-07-04 21:07 胖豆芽 阅读(6) 评论(0) 推荐(0) 编辑
摘要:# for 循环 for letter in 'Names': print(letter) ''' N a m e s ''' name_list=['walter','Nicole','d'] for name in name_list: print(name) ''' walter Nicole 阅读全文
posted @ 2023-07-04 20:46 胖豆芽 阅读(1) 评论(0) 推荐(0) 编辑
摘要:# 字典 给字典赋值dict3={}dict3[1]='abc'dict3['1']=3.1215926dict3[3.2]='xyz'print(dict3) # {1: 'abc', '1': 3.1215926, 3.2: 'xyz'}# 修改dict3[1]="ggg"print(dict3 阅读全文
posted @ 2023-07-04 19:22 胖豆芽 阅读(16) 评论(0) 推荐(0) 编辑
摘要:# 字符串的格式化 name='fqs'print('%s'%(name)) # fqs name="fqs" hobby="hiking" print("hello,my name is %s,I like %s "%(name,hobby)) # 字符串的转义字符 print(r"\4f\x5O 阅读全文
posted @ 2023-07-04 18:27 胖豆芽 阅读(12) 评论(0) 推荐(0) 编辑
摘要:# 给定两个字符串 str1 =“abc” str2="abcd" 只包含小写字母 # str2中和str1不一样的字母是? str1="abc" str2="abcd" dif=[] for letter in str2: if letter not in str1: dif.append(let 阅读全文
posted @ 2023-07-03 20:59 胖豆芽 阅读(4) 评论(0) 推荐(0) 编辑
摘要:# 规律 aabb ;单词 cat cat dog dog ;符合规律 返回true。 # 学习map 方法 # 将列表中的每个元素转换为 字符串 str(number_list[下标]) number_list=[1,2,3,4,5,6] #将下标=0的元素 转字符串 某个字符串=str(numb 阅读全文
posted @ 2023-07-03 17:30 胖豆芽 阅读(158) 评论(0) 推荐(0) 编辑
摘要:# 规律 aabb ;单词 cat cat dog dog ;符合规律 返回true。 def wordPattern(规律: str, 给定字符串: str) : res=给定字符串.split() return list(map(规律.index, 规律))==list(map(res.inde 阅读全文
posted @ 2023-07-01 22:21 胖豆芽 阅读(4) 评论(0) 推荐(0) 编辑
摘要:# 切片 步长写-1时,表反向输出 str_yuan = "运命重尊,然自其顺的余其,的做能己自做" # 倒叙 str1 = str_yuan[::-1] # 截取 start_index = str1.find("顺") end_index = str1.find(",尊") result = s 阅读全文
posted @ 2023-07-01 19:34 胖豆芽 阅读(8) 评论(0) 推荐(0) 编辑
摘要:# 切片 list = [0,1,2,3,4] result=list[1:4]#包头1不包尾4 print(result)# 1,2,3 默认值 起: 0 结束:len(list) ;list 或者tuple 字符串的长度 # 切片 从头到尾的时候可以不写 list= [0, 1, 2, 3, 4 阅读全文
posted @ 2023-07-01 17:41 胖豆芽 阅读(10) 评论(0) 推荐(0) 编辑
摘要:印度传说 def move(起始塔当前金盘数量, 起始塔, 目标塔, 辅助塔): if 起始塔当前金盘数量 > 0: # 将n-1个金盘从起始塔移动到辅助塔 move(起始塔当前金盘数量 - 1, 起始塔, 辅助塔, 目标塔) if 起始塔当前金盘数量==1: print(f"移动小盘子 从 {起始 阅读全文
posted @ 2023-07-01 17:33 胖豆芽 阅读(18) 评论(0) 推荐(0) 编辑