使用Python在Word中创建、读取和删除列表 - 详解

embedded/2025/3/31 11:17:40/

目录

工具与设置

Python%E5%9C%A8Word%E4%B8%AD%E5%88%9B%E5%BB%BA%E5%88%97%E8%A1%A8-toc" name="tableOfContents" style="margin-left:40px">Python在Word中创建列表

使用默认样式创建有序(编号)列表

使用默认样式创建无序(项目符号)列表

创建多级列表

使用自定义样式创建列表

Python%E8%AF%BB%E5%8F%96Word%E4%B8%AD%E7%9A%84%E5%88%97%E8%A1%A8-toc" name="tableOfContents" style="margin-left:40px">Python读取Word中的列表

Python%E4%BB%8EWord%E4%B8%AD%E5%88%A0%E9%99%A4%E5%88%97%E8%A1%A8-toc" name="tableOfContents" style="margin-left:40px">Python从Word中删除列表


在Word中,列表是一种用于组织和呈现信息的有效工具。它们不仅可以帮助用户清晰地展示数据、概念或步骤,还能增强文档的可读性和专业性。通过使用列表,用户能够更直观地理解信息之间的关系,尤其是在处理复杂内容时。在这篇博客中,我们将探讨如何使用PythonWord文档中创建、读取和删除列表,主要涉及的内容如下:

  • Python在Word中创建列表
    • 使用默认样式创建有序(编号)列表
    • 使用默认样式创建无序(项目符号)列表
    • 创建多级列表
    • 使用自定义样式创建列表
  • Python读取Word中的列表
  • Python从Word中删除列表

工具与设置

要使用PythonWord文档中创建和操作列表,可以使用Free Spire.Doc for Python库。它是一个免费的Word文档处理库,主要用于在Python应用程序中生成、读取、编辑和转换Word文档

在开始之前,请通过以下命令安装该库:

pip install Spire.Doc.Free

Python%E5%9C%A8Word%E4%B8%AD%E5%88%9B%E5%BB%BA%E5%88%97%E8%A1%A8" name="Python%E5%9C%A8Word%E4%B8%AD%E5%88%9B%E5%BB%BA%E5%88%97%E8%A1%A8" style="margin-left:.0001pt; margin-right:0">Python在Word中创建列表

Microsoft Word提供了多种列表选项,包括有序(编号)列表、无序(项目符号)列表和多级列表。用户可以使用默认样式创建列表,也可以根据自己的需求自定义列表的外观,例如,可以选择不同的编号格式或项目符号样式,以便更好地匹配文档的整体设计和风格。

接下来,我们将逐一介绍如何使用Python在Word中创建这些列表。

使用默认样式创建有序(编号)列表

有序列表,也称为编号列表,它使用数字或字母标识项目,主要用于按特定顺序呈现步骤、排名或时间线等信息。

要在Word文档中创建有序(编号)列表,只需使用 Section.AddParagraph() 方法添加段落,然后通过 Paragraph.ListFormat.ApplyNumberedStyle() 方法为这些段落应用默认的编号列表样式。

以下是具体的实现步骤:

  • 初始化Document类的实例来创建一个新的Word文档
  • 使用Document.AddSection()方法向文档添加一个节。
  • 创建一个List,用于存放生成列表的项目。
  • 遍历List。
    • 使用Section.AddParagraph()方法为当前列表项添加一个段落。
    • 使用Paragraph.AppendText()方法将当前列表项的文本内容添加到段落。
    • 使用Paragraph.ListFormat.ApplyNumberedStyle()方法为段落应用默认的编号列表样式。
  • 使用Document.SaveToFile()方法保存文档。

实现代码

以下代码展示了如何使用PythonWord文档中使用默认样式创建有序(编号)列表:

from spire.doc import *# 创建新的Word文档
doc = Document()
# 向文档添加一个节
section = doc.AddSection()
section.PageSetup.Margins.All = 72# 添加一个标题段落
para = section.AddParagraph()
para.Format.AfterSpacing = 5.0
text_range = para.AppendText("有序列表示例:")
text_range.CharacterFormat.FontName = "宋体"# 创建项目列表
items = ["有序列表项目1", "有序列表项目2", "有序列表项目3"]# 将每个项目作为编号列表添加到文档中
for item in items:# 为每个项目添加一个段落para = section.AddParagraph()text_range = para.AppendText(item)text_range.CharacterFormat.FontName = "宋体"# 将默认编号列表样式应用于段落para.ListFormat.ApplyNumberedStyle()# 保存文档
doc.SaveToFile("默认有序列表.docx", FileFormat.Docx2016)
doc.Close()

<a class=Python在Word中创建编号列表" height="250" src="https://i-blog.csdnimg.cn/direct/e96e8c0657cb423097566a284dde60a4.png" width="500" />

使用默认样式创建无序(项目符号)列表

无序列表,也叫做项目符号列表,它使用符号(如圆点或方块)标识项目,强调项目之间的关联性而不关心顺序,适用于列出相关特性或要点。

要在Word文档中创建无序(项目符号)列表,可以使用Section.AddParagraph()Paragraph.ListFormat.ApplyBulletStyle()方法。具体的实现步骤与创建有序(编号)列表基本相同,此处不再详细说明。

实现代码

以下代码展示了如何使用PythonWord文档中使用默认样式创建无序(项目符号)列表:

from spire.doc import *# 创建新的Word文档
doc = Document()
# 向文档添加一个节
section = doc.AddSection()
section.PageSetup.Margins.All = 72# 添加一个标题段落
para = section.AddParagraph()
para.Format.AfterSpacing = 5.0
text_range = para.AppendText("无序列表示例:")
text_range.CharacterFormat.FontName = "宋体"# 创建项目列表
items = ["无序列表项目1", "无序列表项目2", "无序列表项目3"]# 将每个项目作为项目符号列表添加到文档中
for item in items:# 为每个项目添加一个段落para = section.AddParagraph()text_range = para.AppendText(item)text_range.CharacterFormat.FontName = "宋体"# 将默认项目符号列表样式应用于段落para.ListFormat.ApplyBulletStyle()    # 保存文档
doc.SaveToFile("默认无序列表.docx", FileFormat.Docx2016)
doc.Close()

<a class=Python在Word中创建项目符号列表" height="250" src="https://i-blog.csdnimg.cn/direct/15dda9831a0845928a72faa2a7dceb44.png" width="500" />

创建多级列表

多级列表是一种包含多个层级的列表结构,允许在同一列表中结合有序和无序项目,以展示信息的层次关系和分类,使内容更加清晰和有条理。适用于创建大纲、分类数据或构建具有多个缩进级别的详细列表。

Spire.Doc主要提供了两种方法来管理多级列表的级别:

  1. 直接设置列表级别
    使用Paragraph.ListFormat.ListLevelNumber属性直接定义每个段落的列表级别。该属性接受从0到8的值,其中0表示级别1,8表示级别9。
  2. 调整列表项目的缩进级别
    或者使用Paragraph.ListFormat.IncreaseIndentLevel()Paragraph.ListFormat.DecreaseIndentLevel()方法增加或减少列表项目的缩进级别。

实现代码

方法1:通过直接设置每个段落的列表级别来创建多级列表

from spire.doc import *# 创建新的Word文档
doc = Document()
# 向文档添加一个节
section = doc.AddSection()
section.PageSetup.Margins.All = 72# 添加一个标题段落
para = section.AddParagraph()
para.Format.AfterSpacing = 5.0
text_range = para.AppendText("多级列表示例:")
text_range.CharacterFormat.FontName = "宋体"# 添加段落
para = section.AddParagraph()
text_range = para.AppendText("多级列表 - 级别1")
text_range.CharacterFormat.FontName = "宋体"
# 将默认编号列表样式应用于段落
para.ListFormat.ApplyNumberedStyle()
# 设置列表级别为级别1
para.ListFormat.ListLevelNumber = 0# 添加段落
para = section.AddParagraph()
text_range = para.AppendText("多级列表 - 级别2")
text_range.CharacterFormat.FontName = "宋体"
# 将默认编号列表样式应用于段落
para.ListFormat.ApplyNumberedStyle()
# 设置列表级别为级别2
para.ListFormat.ListLevelNumber = 1# 添加段落
para = section.AddParagraph()
text_range = para.AppendText("多级列表 - 级别1")
text_range.CharacterFormat.FontName = "宋体"
# 将默认编号列表样式应用于段落
para.ListFormat.ApplyNumberedStyle()
# 设置列表级别为级别1
para.ListFormat.ListLevelNumber = 0# 添加段落
para = section.AddParagraph()
text_range = para.AppendText("多级列表 - 级别2")
text_range.CharacterFormat.FontName = "宋体"
# 将默认编号列表样式应用于段落
para.ListFormat.ApplyNumberedStyle()
# 设置列表级别为级别2
para.ListFormat.ListLevelNumber = 1# 添加段落
para = section.AddParagraph()
text_range = para.AppendText("多级列表 - 级别3")
text_range.CharacterFormat.FontName = "宋体"
# 将默认编号列表样式应用于段落
para.ListFormat.ApplyNumberedStyle()
# 设置列表级别为级别3
para.ListFormat.ListLevelNumber = 2# 保存文档
doc.SaveToFile("多级列表.docx", FileFormat.Docx2016)
doc.Close()

<a class=Python在Word中设置段落列表级别来创建多级列表" height="250" src="https://i-blog.csdnimg.cn/direct/df28eeb72184470090417640c91fc81d.png" width="500" />

方法2:通过增加或减少列表项目的缩进级别来创建多级列表

from spire.doc import *# 创建新的Word文档
doc = Document()
# 向文档添加一个节
section = doc.AddSection()
section.PageSetup.Margins.All = 72# 添加一个标题段落
para = section.AddParagraph()
para.Format.AfterSpacing = 5.0
text_range = para.AppendText("多级列表示例:")
text_range.CharacterFormat.FontName = "宋体"# 添加段落
para = section.AddParagraph()
text_range = para.AppendText("多级列表 - 级别1")
text_range.CharacterFormat.FontName = "宋体"
# 将默认编号列表样式应用于段落
para.ListFormat.ApplyNumberedStyle()# 添加段落
para = section.AddParagraph()
text_range = para.AppendText("多级列表 - 级别2")
text_range.CharacterFormat.FontName = "宋体"
# 增加缩进级别
para.ListFormat.IncreaseIndentLevel()
# 继续上一个列表
para.ListFormat.ContinueListNumbering()# 添加段落
para = section.AddParagraph()
text_range = para.AppendText("多级列表 - 级别1")
text_range.CharacterFormat.FontName = "宋体"
# 减少缩进级别
para.ListFormat.DecreaseIndentLevel()
# 继续上一个列表
para.ListFormat.ContinueListNumbering()# 添加段落
para = section.AddParagraph()
text_range = para.AppendText("多级列表 - 级别2")
text_range.CharacterFormat.FontName = "宋体"
# 增加缩进级别
para.ListFormat.IncreaseIndentLevel()
# 继续上一个列表
para.ListFormat.ContinueListNumbering()# 添加段落
para = section.AddParagraph()
text_range = para.AppendText("多级列表 - 级别3")
text_range.CharacterFormat.FontName = "宋体"
# 增加缩进级别
para.ListFormat.IncreaseIndentLevel()
# 继续上一个列表
para.ListFormat.ContinueListNumbering()# 保存文档
doc.SaveToFile("多级列表.docx", FileFormat.Docx2016)
doc.Close()

<a class=Python在Word中调整缩进级别创建多级列表" height="272" src="https://i-blog.csdnimg.cn/direct/f2c6265b843d43438c525d096475192b.png" width="555" />

使用自定义样式创建列表

除了默认列表样式外,还可以给列表应用自定义样式。

要实现此功能,首先需要使用ListStyle类创建自定义列表样式,并使用该类的属性自定义其外观。然后使用Document.ListStyles.Add()方法将该列表样式添加到文档中。最后,使用Paragraph.ListFormat.ApplyStyle()方法将该列表样式应用于段落。

实现代码

以下代码展示了如何使用PythonWord文档中创建自定义样式的编号列表

from spire.doc import *# 创建新的Word文档
doc = Document()
# 向文档添加一个部分
section = doc.AddSection()
section.PageSetup.Margins.All = 72# 添加一个标题段落
para = section.AddParagraph()
text_range = para.AppendText("自定义编号列表示例:")
# 设置标题字体
text_range.CharacterFormat.FontName = "宋体"
para.Format.AfterSpacing = 5.0# 创建自定义编号列表样式,指定第一级的编号前缀、后缀和编号类型
listStyle = ListStyle(doc, ListType.Numbered)
listStyle.Name = "自定义样式"
listStyle.Levels[0].NumberPrefix = "("
listStyle.Levels[0].NumberSufix = ")"
listStyle.Levels[0].PatternType = ListPatternType.Arabic# 将列表样式添加到文档
doc.ListStyles.Add(listStyle)# 添加段落并应用自定义列表样式
para = section.AddParagraph()
text_range = para.AppendText("自定义列表项目1")
text_range.CharacterFormat.FontName = "宋体"
para.ListFormat.ApplyStyle("自定义样式")
para.ListFormat.ListLevelNumber = 0para = section.AddParagraph()
text_range = para.AppendText("自定义列表项目2")
text_range.CharacterFormat.FontName = "宋体"
para.ListFormat.ApplyStyle("自定义样式")
para.ListFormat.ListLevelNumber = 0para = section.AddParagraph()
text_range = para.AppendText("自定义列表项目3")
text_range.CharacterFormat.FontName = "宋体"
para.ListFormat.ApplyStyle("自定义样式")
para.ListFormat.ListLevelNumber = 0para = section.AddParagraph()
text_range = para.AppendText("自定义列表项目4")
text_range.CharacterFormat.FontName = "宋体"
para.ListFormat.ApplyStyle("自定义样式")
para.ListFormat.ListLevelNumber = 0# 保存文档
doc.SaveToFile("自定义编号列表.docx", FileFormat.Docx2016)
doc.Dispose()

<a class=Python在Word中创建自定义编号列表" height="250" src="https://i-blog.csdnimg.cn/direct/02b0be5f4ad141a1885f7009bb967c62.png" width="510" />

以下代码展示了如何在Python中创建自定义样式的项目符号列表

from spire.doc import *# 创建新的Word文档
doc = Document()
# 向文档添加一个节
section = doc.AddSection()
section.PageSetup.Margins.All = 72# 添加一个标题段落
para = section.AddParagraph()
para.Format.AfterSpacing = 5.0
text_range = para.AppendText("自定义项目符号列表示例:")
# 设置标题字体
text_range.CharacterFormat.FontName = "宋体"# 创建自定义项目符号列表样式,指定第一级的项目符号字符和字体
listStyle = ListStyle(doc, ListType.Bulleted)
listStyle.Name = "自定义样式"
listStyle.Levels[0].BulletCharacter = "\u002A"
listStyle.Levels[0].CharacterFormat.FontName = "Symbol"# 将列表样式添加到文档
doc.ListStyles.Add(listStyle)# 添加段落并应用自定义列表样式
para = section.AddParagraph()
text_range = para.AppendText("自定义列表项目1")
text_range.CharacterFormat.FontName = "宋体"
para.ListFormat.ApplyStyle("自定义样式")
para.ListFormat.ListLevelNumber = 0para = section.AddParagraph()
text_range = para.AppendText("自定义列表项目2")
text_range.CharacterFormat.FontName = "宋体"
para.ListFormat.ApplyStyle("自定义样式")
para.ListFormat.ListLevelNumber = 0para = section.AddParagraph()
text_range = para.AppendText("自定义列表项目3")
text_range.CharacterFormat.FontName = "宋体"
para.ListFormat.ApplyStyle("自定义样式")
para.ListFormat.ListLevelNumber = 0# 保存文档
doc.SaveToFile("自定义项目符号列表.docx", FileFormat.Docx2016)
doc.Dispose()

<a class=Python在Word中创建自定义项目符号列表" height="251" src="https://i-blog.csdnimg.cn/direct/6f13509ddc934d8c945afa18ef3f5796.png" width="510" />

以下代码展示了如何在Python中创建带前一级编号前缀的多级编号列表

from spire.doc import *# 创建新的Word文档
doc = Document()
# 向文档添加一个节
section = doc.AddSection()
section.PageSetup.Margins.All = 72# 添加一个标题段落
para = section.AddParagraph()
para.Format.AfterSpacing = 5.0
text_range = para.AppendText("自定义多级列表示例:")
# 设置标题字体
text_range.CharacterFormat.FontName = "宋体"# 创建自定义编号列表样式,指定特定级别的编号前缀和编号类型
listStyle = ListStyle(doc, ListType.Numbered)
listStyle.Name = "自定义样式"
listStyle.Levels[0].PatternType = ListPatternType.Arabic
# NumberPrefix的值应满足语法"%n",以将上一级列表值更新为当前级别的前缀
listStyle.Levels[1].NumberPrefix = "%1."
listStyle.Levels[1].PatternType = ListPatternType.Arabic
listStyle.Levels[2].NumberPrefix = "%1.%2."
listStyle.Levels[2].PatternType = ListPatternType.Arabic# 将列表样式添加到文档
doc.ListStyles.Add(listStyle)# 添加段落并应用自定义列表样式
para = section.AddParagraph()
text_range = para.AppendText("自定义列表 - 级别 1")
text_range.CharacterFormat.FontName = "宋体"
para.ListFormat.ApplyStyle("自定义样式")
para.ListFormat.ListLevelNumber = 0para = section.AddParagraph()
text_range = para.AppendText("自定义列表 - 级别 1")
text_range.CharacterFormat.FontName = "宋体"
para.ListFormat.ApplyStyle("自定义样式")
para.ListFormat.ListLevelNumber = 0para = section.AddParagraph()
text_range = para.AppendText("自定义列表 - 级别 2")
text_range.CharacterFormat.FontName = "宋体"
para.ListFormat.ApplyStyle("自定义样式")
para.ListFormat.ListLevelNumber = 1para = section.AddParagraph()
text_range = para.AppendText("自定义列表 - 级别 2")
text_range.CharacterFormat.FontName = "宋体"
para.ListFormat.ContinueListNumbering()
para.ListFormat.ApplyStyle("自定义样式")para = section.AddParagraph()
text_range = para.AppendText("自定义列表 - 级别 3")
text_range.CharacterFormat.FontName = "宋体"
para.ListFormat.ApplyStyle("自定义样式")
para.ListFormat.ListLevelNumber = 2para = section.AddParagraph()
text_range = para.AppendText("自定义列表 - 级别 1")
text_range.CharacterFormat.FontName = "宋体"
para.ListFormat.ApplyStyle("自定义样式")
para.ListFormat.ListLevelNumber = 0# 保存文档
doc.SaveToFile("自定义多级编号列表.docx", FileFormat.Docx2016)
doc.Dispose()

<a class=Python在Word中创建自定义多级编号列表" height="318" src="https://i-blog.csdnimg.cn/direct/ae4d378503b54cd1948a5d524bff405c.png" width="583" />

Python%E8%AF%BB%E5%8F%96Word%E4%B8%AD%E7%9A%84%E5%88%97%E8%A1%A8" name="Python%E8%AF%BB%E5%8F%96Word%E4%B8%AD%E7%9A%84%E5%88%97%E8%A1%A8" style="margin-left:.0001pt; margin-right:0">Python读取Word中的列表

要从Word文档中获取列表,你需要遍历段落并判断它们是否应用了列表格式。对于具有列表格式的段落,你可以通过以下属性获取列表的详细信息,例如列表编号或项目符号、列表项的文本内容、列表类型和嵌套级别:

  • Paragraph.ListText:获取列表编号或项目符号。
  • Paragraph.Text:获取列表项的文本内容。
  • Paragraph.ListFormat.ListType:获取列表的类型(例如,编号、项目符号)。
  • Paragraph.ListFormat.ListLevelNumber:获取列表项的嵌套级别(从0开始)。

实现代码

以下代码展示了如何使用PythonWord文档中获取列表:

from spire.doc import *# 打开现有的Word文档
doc = Document()
doc.LoadFromFile("多级列表.docx")# 获取第一个节
section = doc.Sections[0]# 遍历节中的段落
for para_index in range(section.Paragraphs.Count):para = section.Paragraphs[para_index]# 查找具有列表格式的段落if(para.ListFormat.ListType != ListType.NoList):      # 提取列表编号或项目符号、列表项的文本内容、列表类型和嵌套级别     print(f"列表编号和内容: {para.ListText + para.Text}")print(f"列表类型: {para.ListFormat.ListType}")print(f"列表级别: {para.ListFormat.ListLevelNumber + 1}")doc.Close()

<a class=Python获取Word文档中的列表" height="305" src="https://i-blog.csdnimg.cn/direct/6b24f7869f8147eabc0ee4b09f6e565c.png" width="495" />

Python%E4%BB%8EWord%E4%B8%AD%E5%88%A0%E9%99%A4%E5%88%97%E8%A1%A8" name="Python%E4%BB%8EWord%E4%B8%AD%E5%88%A0%E9%99%A4%E5%88%97%E8%A1%A8" style="margin-left:.0001pt; margin-right:0">Python从Word中删除列表

如果你需要清除Word段落的列表格式,只需调用Paragraph.ListFormat.RemoveList()方法。该方法将从段落中删除项目符号或编号,同时保留文本。

实现代码

以下代码展示了如何使用Python清除Word段落的列表格式:

from spire.doc import *# 打开现有的Word文档
doc = Document()
doc.LoadFromFile("多级列表.docx")# 获取第一个节
section = doc.Sections[0]# 从段落中删除列表格式
for para_index in range(section.Paragraphs.Count):para = section.Paragraphs[para_index]if(para.ListFormat.ListType != ListType.NoList):      para.ListFormat.RemoveList()# 保存文档
doc.SaveToFile("删除列表.docx", FileFormat.Docx2016)
doc.Dispose()

<a class=Python清除Word文档中的列表格式" height="264" src="https://i-blog.csdnimg.cn/direct/f10fc50fe6d64e4c94ea2b1e2e5dea07.png" width="510" />

以上就是使用Python在Word中创建、获取和操作列表的全部内容。感谢阅读!


http://www.ppmy.cn/embedded/174685.html

相关文章

洛谷题目:P1018 [NOIP 2000 提高组] 乘积最大 题解

题目传送门&#xff1a; P1018 [NOIP 2000 提高组] 乘积最大 - 洛谷 (luogu.com.cn) 前言&#xff1a; 本题可以使用DP来解决。动态规划的核心思想是将一个复杂的问题分解为多个简单的子问题&#xff0c;并通过求解子问题的最优解来得到原问题的最优解。在本题中&#xff0c…

高频SQL50题 第一天 | 1757. 可回收且低脂的产品、584. 寻找用户推荐人、595. 大的国家、1683. 无效的推文、1148. 文章浏览 I

1757. 可回收且低脂的产品 题目链接&#xff1a;https://leetcode.cn/problems/recyclable-and-low-fat-products/description/?envTypestudy-plan-v2&envIdsql-free-50 状态&#xff1a;已完成 考点&#xff1a;无 select product_id from Products where low_fats Y a…

DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加导出数据功能

前言:哈喽,大家好,今天给大家分享一篇文章!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕 目录 DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加导出数据功能📚页面效果📚指令输入�…

Windows 事件日志中登录类型(Logon Type)

Windows 登录类型&#xff08;Logon Type&#xff09;用于标识用户通过何种方式登录到系统&#xff0c;在安全审计日志&#xff08;如Windows事件日志&#xff09;中记录不同的登录行为。以下是常见的登录类型及其含义&#xff1a; 常见登录类型 交互式登录&#xff08;Interac…

Pytest的数据驱动DDT

1、ddt的语法&#xff1a; pytest.mark.parametrize(“case”, case_all) 是个装饰器&#xff0c;里面两个数据&#xff1a; case 和cases_all意思就是&#xff1a; 将cases_all里每个成员依次传递给case这个变 量&#xff1b; cace注意要加引号&#xff0c;虽然是个变量 但是要…

Java学习笔记-XXH3哈希算法

XXH3是由Yann Collet设计的非加密哈希算法&#xff0c;属于XXHash系列的最新变种&#xff0c;专注于极速性能与低碰撞率&#xff0c;适用于对计算效率要求极高的场景。 极速性能 在RAM速度限制下运行&#xff0c;小数据&#xff08;如 1-128 字节&#xff09;处理可达纳秒级&…

验证码设计与前端安全:实现方式、挑战与未来发展趋势深度分析

验证码&#xff08;CAPTCHA&#xff09;是一种用于区分人类用户和自动化程序&#xff08;如机器人&#xff09;的技术&#xff0c;广泛应用于登录、注册、表单提交等场景。然而&#xff0c;验证码的设计和实现不仅关乎用户体验&#xff0c;还涉及到前端安全问题。 1. 验证码的…

机器学习之KL散度推导

机器学习之KL散度推导 预备知识 熵、交叉熵、条件熵 熵 (Entropy) 这一词最初来源于热力学。1948年&#xff0c;克劳德爱尔伍德香农将热力学中的熵引入信息论&#xff0c;所以也被称为香农熵 (Shannon entropy)、信息熵 (information entropy)。 对于具体熵的定义和用法推荐…