2021年12月22日
摘要: # 1. 连接数据库, import pymysql conn = pymysql.connect( host='localhost', user='root', password='redhat', db='helloTest', charset='utf8', # autocommit=True 阅读全文
posted @ 2021-12-22 14:54 xxxxaaa 阅读(63) 评论(0) 推荐(0) 编辑
摘要: # 日志 # logger:日志器 程序入口 别的文件想要调用日志 # handlers 处理器 日志信息显示在哪里,多个 # formatter:格式 日志信息变得准确好看 # 日志级别 反应出问题的验证程度 # debug:调试级别 1 级别 # info :正常的 2级别 # warning: 阅读全文
posted @ 2021-12-22 14:47 xxxxaaa 阅读(91) 评论(0) 推荐(0) 编辑
摘要: 冒泡排序 重复遍历要排序的数据,一次比较两个元素,如果他们的顺序错误就交换比较相邻的元素 list1=[6,7,8,3,5,9,4] # 获得总共有多少数据 len1=len(list1) print(len1) # 循环 第一个循环控制循环总共循环的次数 for i in range(1,len1 阅读全文
posted @ 2021-12-22 14:43 xxxxaaa 阅读(98) 评论(0) 推荐(0) 编辑
摘要: 装饰器 闭包函数 闭包函数:变量 函数销毁之后,有时候需要这个函数的变量 闭包解决这个问题 形成条件1.实现函数嵌套2.内部函数使用外部函数的变量3.外部函数返回内部函数 简单的闭包 # 外部函数 def test1(): b=10 # 内部函数 def test2(): print(b) retu 阅读全文
posted @ 2021-12-22 14:37 xxxxaaa 阅读(48) 评论(0) 推荐(0) 编辑
摘要: 面向对象三大特征:封装 继承 多态封装:属性和方法封装在抽象类中 具体出来一个实物 例化 # 继承 class Animal: def eat(self): print('动物有吃的功能') def sleep(self): print('动物有睡觉') # 继承父类Animal class Dog 阅读全文
posted @ 2021-12-22 11:48 xxxxaaa 阅读(38) 评论(0) 推荐(0) 编辑
摘要: # coding=utf-8'''class 类名: 属性 特征''' class Cat: cat_color='白色' cat_foot=4 cat_weight=20 def eat(self): #self 代表创建的对象,能够区分调用的对象是谁 print(f'{self.name}小猫吃 阅读全文
posted @ 2021-12-22 11:36 xxxxaaa 阅读(40) 评论(0) 推荐(0) 编辑
摘要: # encoding: UTF-8 # 异常处理 ''' try: 要执行的代码 except: 出现错误的代码 ''' while True: try: num = int(input('请输入整数:')) result = 5/num print('%d可以被整除'%result) break 阅读全文
posted @ 2021-12-22 11:33 xxxxaaa 阅读(75) 评论(0) 推荐(0) 编辑
摘要: 文件名:aa.scv 编号,姓名,年龄,性别1,账单,16,男2,里斯,17,女3,王五,18,男4,赵六,19,男 # 读取csv import csv # 打开文件 with open('./data/aa.csv','r') as f: csv.reader(f) print(f) for i 阅读全文
posted @ 2021-12-22 11:20 xxxxaaa 阅读(86) 评论(0) 推荐(0) 编辑
摘要: excel 文件读取 xlrd xlwt pandas openpyxl openpyxl 操作excel 文件:bb.xlsx import openpyxl # 加载工作簿 wb = openpyxl.load_workbook(r'./data/bb.xlsx') print(wb) # 指定 阅读全文
posted @ 2021-12-22 11:13 xxxxaaa 阅读(49) 评论(0) 推荐(0) 编辑
摘要: # yaml文件读取# 创建yaml文件# 语法规则:字典类型的数据 键: 值 冒号后要空格 文件名:test.yaml文件内容:id: 1name: '张三'age: 18sex: '女' import yaml # 打开文件 f = open('./data/test.yaml','r',enc 阅读全文
posted @ 2021-12-22 10:52 xxxxaaa 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 文件处理和os模块文件操作步骤1.打开文件 open(文件路径,访问模式)2.读取数据,写入数据 read write3.关闭文件 close open(文件路径,访问模式)文件路径:相对路径:相对于你的位置 绝对路径:详细地址 f = open('test.txt', 'w') f.write(' 阅读全文
posted @ 2021-12-22 10:48 xxxxaaa 阅读(75) 评论(0) 推荐(0) 编辑
摘要: # --*--code --*--# @time: 2021/11/1:21:15# @author: # @file:demo5.py# 函数# 步骤# 1.封装函数 独立功能# 2.调用函数# 3.提高代码效率语法:'''def 函数名(): 逻辑代码a''' 两个数字相加 def sum(a, 阅读全文
posted @ 2021-12-22 10:32 xxxxaaa 阅读(51) 评论(0) 推荐(0) 编辑
摘要: 条件判断 运算符 1.比较运算符 : == != <= >= < > 2.算术运算符: + - * / % 3.赋值运算符: += -= *= /= 4.逻辑运算符: and or not 两个表达式进行判断 and:两个条件都为真 x==y and x<z or:两个表达是有一个为真 not:表达 阅读全文
posted @ 2021-12-22 10:22 xxxxaaa 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 不可变数据类型:字符串 数字 元组可变的数据类型:字典 列表 集合元组:定义()标识,里面任意数据类型 以,隔开 tup1 = () print(tup1, type(tup1)) tup1 = (1, '1', [1, 2, 3], True) # 元组里面只有1个数据,后面加, tup2 = ( 阅读全文
posted @ 2021-12-22 10:04 xxxxaaa 阅读(71) 评论(0) 推荐(0) 编辑
摘要: 数据类型:内存地址可变的:字典dict,列表list、集合set不可变:数字number,字符串string,元组tuple不可变数字 整形 int,小数 float 1.4, bool:true 1,false 0 a = 1 print(a) 数据类型 type() print(type(a)) 阅读全文
posted @ 2021-12-22 09:34 xxxxaaa 阅读(258) 评论(0) 推荐(0) 编辑