首页
统计
关于
Search
1
Sealos3.0离线部署K8s集群
1,073 阅读
2
类的加载
737 阅读
3
Spring Cloud OAuth2.0
725 阅读
4
SpringBoot自动装配原理
689 阅读
5
集合不安全问题
582 阅读
笔记
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
Linux
容器
Docker
Kubernetes
Python
登录
Search
标签搜索
Java
CSS
mysql
RabbitMQ
JavaScript
Redis
JVM
Mybatis-Plus
Camunda
多线程
CSS3
Python
Spring Cloud
注解和反射
Activiti
工作流
SpringBoot
Mybatis
Spring
html5
蘇阿細
累计撰写
388
篇文章
累计收到
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
Linux
容器
Docker
Kubernetes
Python
页面
统计
关于
搜索到
10
篇与
的结果
2025-03-18
面向对象
1. 类# 类 class Person(object): # object 基类 pass # 创建对象(类的实例化) student = Person() print(type(student)) # <class '__main__.Person'> print(isinstance(student, object)) print(isinstance(student, Person)) 2. 实例属性# 实例属性 class Person(object): def __init__(self, name, age, address): self.name = name self.age = age self.address = address student = Person('孙笑川', 33, '成都') student.job = '主播' print(student.__dict__) # 获取实例的所有属性 3. 类属性# 类属性 class Person(object): index = 0 # 类属性 def __init__(self, name, age, address): self.name = name self.age = age self.address = address Person.index += 1 if age < 0 or age > 100: raise Exception('年龄有误,请检查!') try: student = Person('孙笑川', 33, '成都') print(student.__dict__) print('第%d个用户' % Person.index) student1 = Person('刘波', 30, '湖北') print(student1.__dict__) print('第%d个用户' % Person.index) except Exception as e: print(e) 4. 实例方法# 实例方法 class Person(object): index = 0 # 类属性 def __init__(self, name, age, address): self.name = name self.age = age self.address = address Person.index += 1 # print('第%d个用户' % Person.index) # 实例方法 def say_hello(self): print('大家好,我是%s' % self.name) try: student = Person('孙笑川', 33, '成都') # print(student.__dict__) student.say_hello() student1 = Person('刘波', 30, '湖北') # print(student1.__dict__) except Exception as e: print(e) 5. 类方法# 类方法 class Person(object): index = 0 # 类属性 def __init__(self, name, age, address): self.name = name self.age = age self.address = address Person.index += 1 if age < 0 or age > 100: raise Exception('年龄有误,请检查!') # 实例方法 def say_hello(self): print('大家好,我是%s' % self.name) # 类方法 @classmethod def get_user_no(cls): print('第%d个用户' % cls.index) try: student = Person('孙笑川', 33, '成都') # print(student.__dict__) student.say_hello() student1 = Person('刘波', 30, '湖北') # print(student1.__dict__) Person.get_user_no() except Exception as e: print(e) 6. 静态方法# 静态方法 class Person(object): index = 0 # 类属性 def __init__(self, name, age, address): self.name = name self.age = age self.address = address Person.index += 1 if age < 0 or age > 100: raise Exception('年龄有误,请检查!') # 实例方法 def say_hello(self): print('大家好,我是%s' % self.name) # 类方法 @classmethod def get_user_no(cls): print('第%d个用户' % cls.index) # 静态方法 @staticmethod def is_valid(**kwargs): if kwargs['token'] == '123456': return True else: print('前置校验失败') return False try: check_key = {'token': '123456'} if Person.is_valid(**check_key): student = Person('孙笑川', 33, '成都') # print(student.__dict__) student.say_hello() student1 = Person('刘波', 30, '湖北') # print(student1.__dict__) Person.get_user_no() else: print('创建用户失败') except Exception as e: print(e) 7. 继承# 继承 class Person(object): index = 0 # 类属性 def __init__(self, name, age, address): self.name = name self.age = age self.address = address Person.index += 1 if age < 0 or age > 100: raise Exception('年龄有误,请检查!') # 实例方法 def say_hello(self): print('大家好,我是%s' % self.name) # 类方法 @classmethod def get_user_no(cls): print('第%d个用户' % cls.index) # 静态方法 @staticmethod def is_valid(**kwargs): if kwargs['token'] == '123456': return True else: print('前置校验失败') return False class People(Person): # 重写父类的 say_hello 方法 def say_hello(self): print('大家好,我是%s,我来自%s' % (self.name, self.address)) try: check_key = {'token': '123456'} if Person.is_valid(**check_key): student = Person('孙笑川', 33, '成都') # print(student.__dict__) student.say_hello() student1 = People('刘波', 30, '湖北') # print(student1.__dict__) student1.say_hello() else: print('创建用户失败') except Exception as e: print(e) 8. 多态# 多态 class Animal(object): def say(self): print('Animal Say...') class Dog(Animal): def say(self): print('汪汪汪...') class Cat(Animal): def say(self): print('喵喵喵...') animal = Animal() animal.say() dog = Dog() dog.say() cat = Cat() cat.say() 9. 封装# 封装 class Person(object): def __init__(self, name, age, address): # self._name = name # 受保护的变量 self.__name = name # 私有变量 self.__age = age self.__address = address if not isinstance(age, int) or age < 0 or age > 100: raise Exception('年龄有误,请检查!') """ 把函数当作变量使用 @property def 变量名(self): # 获取变量 get @变量名.setter def 变量名(self, 变量名): # 设置变量 set """ @property def name(self): return self.__name @name.setter def name(self, name): self.__name = name @property def age(self): return self.__age @age.setter def age(self, age): if not isinstance(age, int) or age < 0 or age > 100: raise Exception('年龄有误,请检查!') else: self.__age = age @property def address(self): return self.__address @address.setter def address(self, address): self.__address = address try: student = Person('孙笑川', 33, '成都') print(student.name) # 修改属性 student.name = '刘波' print(student.__dict__) except Exception as e: print(e)
2025年03月18日
43 阅读
0 评论
0 点赞
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日
16 阅读
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日
21 阅读
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日
21 阅读
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日
20 阅读
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日
16 阅读
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日
16 阅读
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日
19 阅读
0 评论
0 点赞
1
2