网站首页 > 技术文章 正文
datetime模块:提供日期和时间相关的功能。
import datetime
# 获取当前日期和时间
current_time = datetime.datetime.now()
# 格式化日期和时间
formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
# 解析字符串为日期和时间
parsed_time = datetime.datetime.strptime("2022-01-01", "%Y-%m-%d")
7.calendar模块:提供日历相关的功能。
import calendar
# 获取指定月份的日历
cal = calendar.month(2022, 1)
print(cal)
8.logging模块:提供日志记录功能。
import logging
# 配置日志记录器
logging.basicConfig(filename='app.log', level=logging.INFO)
# 记录日志
logging.info('This is an info message')
9.argparse模块:提供命令行参数解析功能。
import argparse
# 创建解析器
parser = argparse.ArgumentParser()
# 添加参数
parser.add_argument('--name', help='Name argument')
# 解析命令行参数
args = parser.parse_args()
# 获取参数值
name = args.name
10.re模块:提供正则表达式匹配功能。
PYTHON复制import re
# 匹配字符串
pattern = r'\b\w+@\w+\.\w+\b'
email = re.match(pattern, 'example@example.com')
# 搜索字符串
matches = re.findall(pattern, 'Contact us at example@example.com or info@example.com')
猜你喜欢
- 2025-06-23 python3实现线程和进程的状态转换的模块及应用示例
- 2025-06-23 原来Python的协程有2种实现方式(python协程gevent)
- 2025-06-23 python线程start、run方法本质和区别
- 2025-06-23 Python常见模块机os、sys、pickle、json、time用法
- 2025-06-23 python类库configparser(python class库)
- 2025-06-23 python字典常用初始化方式、增加元素及遍历
- 2025-06-23 python运算符重载和上下文管理(python重载加号)
- 2025-06-23 《第32天》运维工程师分享:web服务器如何解析python
- 2025-06-23 Linux面试题Python(linux面试题大全)
- 2025-06-23 ZooKeeper分布式服务框架在python开发中常见的应用案例
- 06-23python3实现线程和进程的状态转换的模块及应用示例
- 06-23原来Python的协程有2种实现方式(python协程gevent)
- 06-23python线程start、run方法本质和区别
- 06-23Python模块datetime、calendar、logging、argparse、re用法
- 06-23Python常见模块机os、sys、pickle、json、time用法
- 06-23python类库configparser(python class库)
- 06-23python字典常用初始化方式、增加元素及遍历
- 06-23python运算符重载和上下文管理(python重载加号)
- 270℃Python短文,Python中的嵌套条件语句(六)
- 268℃python笔记:for循环嵌套。end=""的作用,图形打印
- 266℃PythonNet:实现Python与.Net代码相互调用!
- 262℃Python实现字符串小写转大写并写入文件
- 260℃Python操作Sqlserver数据库(多库同时异步执行:增删改查)
- 120℃原来2025是完美的平方年,一起探索六种平方的算吧
- 101℃Python 和 JavaScript 终于联姻了!PythonMonkey 要火?
- 95℃Ollama v0.4.5-v0.4.7 更新集合:Ollama Python 库改进、新模型支持
- 最近发表
-
- python3实现线程和进程的状态转换的模块及应用示例
- 原来Python的协程有2种实现方式(python协程gevent)
- python线程start、run方法本质和区别
- Python模块datetime、calendar、logging、argparse、re用法
- Python常见模块机os、sys、pickle、json、time用法
- python类库configparser(python class库)
- python字典常用初始化方式、增加元素及遍历
- python运算符重载和上下文管理(python重载加号)
- 《第32天》运维工程师分享:web服务器如何解析python
- Linux面试题Python(linux面试题大全)
- 标签列表
-
- python中类 (31)
- python 迭代 (34)
- python 小写 (35)
- python怎么输出 (33)
- python 日志 (35)
- python语音 (31)
- python 工程师 (34)
- python3 安装 (31)
- python音乐 (31)
- 安卓 python (32)
- python 小游戏 (32)
- python 安卓 (31)
- python聚类 (34)
- python向量 (31)
- python大全 (31)
- python次方 (33)
- python桌面 (32)
- python总结 (34)
- python浏览器 (32)
- python 请求 (32)
- python 前端 (32)
- python验证码 (33)
- python 题目 (32)
- python 文件写 (33)
- python中的用法 (32)