首页
统计
关于
Search
1
Sealos3.0离线部署K8s集群
1,272 阅读
2
类的加载
832 阅读
3
Spring Cloud OAuth2.0
827 阅读
4
SpringBoot自动装配原理
735 阅读
5
集合不安全问题
631 阅读
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Canvas
Linux
容器
Docker
Containerd
Kubernetes
Python
FastApi
OpenCV
数据分析
牛牛生活
登录
Search
标签搜索
Java
CSS
mysql
RabbitMQ
JavaScript
Redis
OpenCV
JVM
Mybatis-Plus
Camunda
多线程
CSS3
Python
Canvas
Spring Cloud
注解和反射
Activiti
工作流
SpringBoot
ndarray
蘇阿細
累计撰写
435
篇文章
累计收到
4
条评论
首页
栏目
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Canvas
Linux
容器
Docker
Containerd
Kubernetes
Python
FastApi
OpenCV
数据分析
牛牛生活
页面
统计
关于
搜索到
435
篇与
的结果
2025-03-17
文件及IO操作
1. 读取文件# 读取文件 import os # 绝对路径 # absolute_path = os.getcwd() # file_name = absolute_path + '/test.txt' # f = open(file_name, mode='r', encoding='utf-8') # 相对路径 f = open('test.txt', mode='r', encoding='utf-8') # content = f.read() # 读取全部 # content = f.readline() # 读取一行 content = f.readlines() # 按行读取 print(content) # 关闭 f.close() 2. 写文件# 写文件 f = open('test.txt', mode='w', encoding='utf-8') f.write('大家好\n') write_content = ['孙笑川\n', '刘波\n'] f.writelines(write_content) f.close() f = open('test.txt', mode='r', encoding='utf-8') read_content = f.read() print(read_content) f.close() 3. 追加写# 追加写 f = open('test.txt', mode='a', encoding='utf-8') f.write('你好\n') content = ['带带大师兄\n', '药水哥\n'] f.writelines(content) f.close() 4. with# with open() as f 操作文件 with open('test.txt', mode='r', encoding='utf-8') as f: print(f.read()) print('使用with语法糖读取文件内容完成')
2025年03月17日
44 阅读
0 评论
0 点赞
2025-03-16
模块
此处以 random、正则、socket 为例1. random# random import random # 随机小数 print(random.random()) # 1 - 10 之间的随机数 print(random.randint(1, 10)) 2. 正则# 正则 import re # \d 数字 result = re.match(r'\d+', '123abc') print(result) # 123 # \w 数字、字母、下划线 result = re.match(r'\w+', '1a2b3c!') print(result) # 1a2b3c # \s 空白字符串;\S 非空字符串 result = re.match(r'^\s+$', '1 2 3') print(result) # None result = re.match(r'^\S+$', '1 abc') print(result) # None # . 任意字符 result = re.match(r'.+$', 'abc 1q2') print(result) # abc 1q2 # [] 区间 result = re.match(r'^a[1a]', 'a123456') print(result) # a1 # | 或 result = re.match(r'^a|1|c$', 'a12345c') print(result) # a 3. socket3.1 server# socket import socket sk = socket.socket() sk.bind(('127.0.0.1', 8088)) sk.listen(5) conn, addr = sk.accept() print(conn) print(addr) while True: accept_data = conn.recv(1024) print('收到客户端发送的消息:', accept_data.decode('utf-8')) send_data = input('请输入要回复的消息:') conn.send(send_data.encode('utf-8'))3.2 client# socket import socket sk = socket.socket() sk.connect(('127.0.0.1', 8088)) while True: sand_data = input('请输入要发送的消息:') sk.send(sand_data.encode('utf-8')) accept_data = sk.recv(1024) print(accept_data.decode('utf-8'))
2025年03月16日
46 阅读
0 评论
0 点赞
2025-03-16
函数
1. 函数# 函数 def say_hello(name): print('大家好,我叫', name) say_hello('孙笑川') # 可变参数 def test(*args): print(args) test(1, 2, 3, 4) def test_1(**kwargs): for key, value in kwargs.items(): print(key, value) test_1(**{'name': '孙笑川', 'age': 33, 'address': '成都'}) 2. 变量的作用域# 变量的作用域 # 不可变数据类型 index = 1 # 可变数据类型 list = [1, 2, 3] def test(): global index # 全局变量 index = 20 index1 = 30 list[1] = 300 test() # print('函数执行完后打印index1的值', index1) # 报错 Unresolved reference 'index1' print('函数执行完后打印index的值', index) # 20 print('函数执行完后打印list的值', list) # [1, 300, 3] 3. 匿名函数# 匿名函数 test = lambda x, y: x + y print(test(1, 2)) arr = [1, 2, 3, 4] # 映射 result = map(lambda x: x ** 2, arr) print(list(result)) # 归约 from functools import reduce print(reduce(lambda x, y: x * y, arr)) # 过滤 print(list(filter(lambda x: x % 2 != 0, arr)))
2025年03月16日
45 阅读
0 评论
0 点赞
2025-03-14
异常处理
# 异常处理 try: n = int(input('请输入被除数:')) i = 10 / n print(i) except ZeroDivisionError as e: print('除数不能为0') except: print('请输入正确的数字!') else: print('未被except捕获') finally: print('执行完毕') print('----------------------') # 抛出异常 try: n = input('请输入一个任意数字:') if not n.isdigit(): raise Exception('输入的内容有误,请检查!') else: print('您输入的数字是:%d' % n) except Exception as e: print(e)
2025年03月14日
40 阅读
0 评论
0 点赞
2025-03-14
组合数据类型
1. 列表# 列表 list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] print(list) # 索引 print(list[1]) # 切片 print(list[::-1]) # 内置函数 print(min(list)) print(max(list)) print(len(list)) print('-------------------------') # 遍历 for i in list: print(i) for i, index in enumerate(list): print(i, index) for i in range(len(list)): print(i, list[i]) # 常用方法 # 添加元素 list.append('a') list.extend('extend') print(list) print('-------------------------') # 插入元素 list.insert(1, 'b') print(list) print('-------------------------') # 根据索引删除元素 list.pop(1) print(list) print('-------------------------') # 删除指定元素 list.remove(1) print(list) print('-------------------------') # 清空列表 list.clear() print(list) 2. 元组# 元组 tuple1 = (1, 2, 3, 4, 5, 6) print(type(tuple1)) print(tuple1) temp_tuple = (1,) # 元组中只有一个元素时,加一个逗号 print(type(temp_tuple)) print('-------------------------') # 类型转换 # str ---> tuple print(tuple('abc')) # list ---> tuple print(tuple([1, 2, 3])) print('-------------------------') # 索引 print(tuple1[1]) # 切片 print(tuple1[::-1]) # 常用方法 print(min(tuple1)) print(max(tuple1)) print(len(tuple1)) print('-------------------------') # 遍历 for i in tuple1: print(i) for index, item in enumerate(tuple1): print(index, item) for i in range(len(tuple1)): print(tuple1[i]) 3. 字符串# 字符串 str = 'sunxiaochuan,liubo' print(min(str)) print(max(str)) print(len(str)) print('-------------------------') # 遍历 for i in str: print(i) for index, item in enumerate(str): print(index, item) for i in range(len(str)): print(str[i]) print('-------------------------') # 常用方法 print(str.islower()) print(str.isupper()) print(str.count('c')) print(str.split(',')) print(str.find('l')) 4. 字典# 字典 d = {} print(type(d)) # <class 'dict'> # 新增值(键值对) d['name'] = 'sunxiaochuan' d['age'] = 33 print(d) # 获取键值对 print(d['name']) # 修改 d['age'] = 30 print(d) print('-------------------------') # 遍历 for i in d: print(i, d[i]) for k, v in d.items(): print(f'{k} = {v}') for k in d.keys(): print(k) for value in d.values(): print(value) print('-------------------------') # 常用方法 # d.pop('name') # print(d) new_dictionary = d.copy() print(new_dictionary) name = d.get('name') print(name) # d.popitem() # print(d) d.update({'age': 50}) print(d) 5. 集合# 集合 s = set() s = {1, 2, 3, 4, 5} # s1 = set([1, 2, 3, 4, 5]) # list ---> set # s2 = set((1, 2, 3, 4, 5)) # tuple ---> set # s3 = set('12345') # str ---> list # s4 = set({'key1': 'value1', 'key2': 1}) # dict ---> list # 常用方法 print(1 in s) print(len(s)) print(min(s)) print(max(s)) # del s # 删除集合 s.add('a') print(s) s.remove(1) print(s) s.update({'a', 'b', 'c'}) print(s) print('-------------------------') # 遍历 for i in s: print(i) print('-------------------------') s1 = {1, 2, 3, 'a', 88} s2 = {'c', 'b', 3, 1, 'f'} print(s1 & s2) # 交集 print(s1 | s2) # 并集 print('-------------------------') # 去重 s3 = set([1, 1, 2, 3, 4, 5, 6, 6, 7]) print(s3)
2025年03月14日
41 阅读
0 评论
0 点赞
2025-03-12
循环
1. while# while index = 0 while index < 100: print(index) index += 1 2. for# for for i in range(100): print(i) # 求n的阶乘 result = 0 index = 1 while index <= 5: current_result = 1 m = 1 while m <= index: current_result = current_result * m m += 1 result += current_result index += 1 print("5的阶乘为:%d" % result) 3. break# break for i in range(10): print(i) if i == 3: print("结束循环") break 4. continue# continue for i in range(10): if i == 5: continue print(i)
2025年03月12日
39 阅读
0 评论
0 点赞
2025-03-11
条件判断
1. 单分支# 单分支 flag = 1 if flag == 1: print("标志位为1") if True: print("符合判断条件")2. 双分支# 双分支 flag = 1 if flag == 1: print("标志位为1") else: print("标志位不为1") if True: print("符合判断条件") else: print("不符合判断条件") 3. 多分支# 多分支 flag = 1 if flag == 1: print("标志位为1") elif flag == 2: print("标志位为2") elif flag == 3: print("标志位为3") else: print("未匹配到对应的标志位") 4. match# match flag = 1 match flag: case 1: print("标志位为1") case 2: print("标志位为2") case 3: print("标志位为3") case _: print("未匹配到对应的标志位")
2025年03月11日
48 阅读
0 评论
0 点赞
2025-03-09
运算符与表达式
1. 算术运算符# 算术运算符 a = 1 b = 2 # 加 print(a + b) # 减 print(a - b) # 乘 print(a * b) # 除 print(a / b) # 整除(取整) print(a // b) # 求模 print(a % b) # 幂运算 print(a ** 2) 2. 赋值运算符# 赋值运算符 a = 1 # 自增 a += 1 print(a) # 自减 a -= 1 print(a) 3. 比较运算符# 比较运算符 a = 1 b = 2 # 不等于 != print(a != b) # 等于 == print(a == b) # 字符串比较(比较的是每个字符的ascii码值) print("abc" < "efg") print("abc" == False) 4. 逻辑运算符# 逻辑运算符 # 与 and print(1 and 2) print(False and True) print("abc" and "edg") # 短路运算,按字符顺序比较,当第一个字符 e > a 时,返回edg # 或 or print(1 or 2) print(0 or 1) print(False or True) # 非 not print(not 1) print(not False) print(not "") # 三者之间的优先级关系 not > and > or print(True or False and not False) 5. 位运算符# 位运算符 # 按位与 & ''' 101 111 --- 101 ''' print(5 & 7) # 按位或 | ''' 101 111 --- 111 ''' print(5 | 7) # 按位异或 ''' 101 111 --- 010 ''' print(5 ^ 7) # 按位取反 ~ ''' 101 --- 010 ''' print(~5) # 左移 右移 ''' 101 --- 10100 ''' print(5 << 2) 6. 成员运算符# 成员运算符 str = "这是一个字符串" print("a" in str) a = 1 b = 2 print(a is b) print(a is not b)
2025年03月09日
23 阅读
0 评论
0 点赞
1
...
6
7
8
...
55