提交 994c2eec 编写于 作者: W wizardforcel

2020-06-19 12:24:57

上级 493f0770
......@@ -34,4 +34,4 @@ Python 是一种通用的,动态的,面向对象的编程语言。 Python
## Python 相关教程
您可能对以下教程感兴趣: [PyQt5 教程](/gui/pyqt5/)[Pillow 教程](/python/pillow/)[Tkinter 教程](/tkinter/)[OpenPyXL 教程](/articles/openpyxl/)[wxPython 教程](/wxpython/)[PySide 教程](/gui/pysidetutorial/)[PyGTK 教程](/gui/pygtk/)[Python 请求教程](/web/pythonrequests/)
\ No newline at end of file
您可能对以下教程感兴趣: [PyQt5 教程](/gui/pyqt5/)[Pillow 教程](/python/pillow/)[Tkinter 教程](/tkinter/)[OpenPyXL 教程](/articles/openpyxl/)[wxPython 教程](/wxpython/)[PySide 教程](/gui/pysidetutorial/)[PyGTK 教程](/gui/pygtk/)[Python Requests 教程](/web/pythonrequests/)
\ No newline at end of file
......@@ -2,7 +2,7 @@
> 原文: [http://zetcode.com/python/pymongo/](http://zetcode.com/python/pymongo/)
PyMongo 教程展示了如何使用 Python 编程 MongoDB。 在作者的 Github [存储](https://github.com/janbodnar/pymongo-examples/tree/master)中提供了代码示例。
PyMongo 教程展示了如何使用 Python 编程 MongoDB。 在作者的 Github [](https://github.com/janbodnar/pymongo-examples/tree/master)中提供了代码示例。
MongoDB 是 NoSQL 跨平台的面向文档的数据库。 它是可用的最受欢迎的数据库之一。 MongoDB 由 MongoDB Inc. 开发,并作为免费和开源软件发布。
......
......@@ -731,4 +731,4 @@ with open("index.html", "r") as f:
在本教程中,我们使用了 Python BeautifulSoup 库。
您可能也会对以下相关教程感兴趣: [Pyquery 教程](/python/pyquery)[Python 教程](/lang/python/)[Python 列表推导](/articles/pythonlistcomprehensions/)[OpenPyXL 教程](/articles/openpyxl/)[HTG8 Python 请求教程和 [Python CSV 教程](/python/csv/)
\ No newline at end of file
您可能也会对以下相关教程感兴趣: [Pyquery 教程](/python/pyquery)[Python 教程](/lang/python/)[Python 列表推导](/articles/pythonlistcomprehensions/)[OpenPyXL 教程](/articles/openpyxl/)[HTG8 Python Requests 教程和 [Python CSV 教程](/python/csv/)
\ No newline at end of file
......@@ -485,4 +485,4 @@ FreeBSD Debian NetBSD
在本教程中,我们使用了 python pyquery 库。
您可能也对以下相关教程感兴趣: [jQuery 教程](/web/jquery)[Beautifulsoup 教程](/python/beautifulsoup)[Python 教程](/lang/python/)[Python FTP 教程](/python/ftp/)[HTG8 Python 列表推导, [OpenPyXL 教程](/articles/openpyxl/)[Python 请求教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/)
\ No newline at end of file
您可能也对以下相关教程感兴趣: [jQuery 教程](/web/jquery)[Beautifulsoup 教程](/python/beautifulsoup)[Python 教程](/lang/python/)[Python FTP 教程](/python/ftp/)[HTG8 Python 列表推导, [OpenPyXL 教程](/articles/openpyxl/)[Python Requests 教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/)
\ No newline at end of file
......@@ -438,4 +438,4 @@ print()
在本教程中,我们使用 Python 进行循环。
您可能也对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 设置教程](/python/set/)[Python lambda 函数](/python/lambda/)[Python 列表推导](/articles/pythonlistcomprehensions/)[Python 映射教程](/python/map/)[Python 反向教程](/python/reverse/)[OpenPyXL 教程](/articles/openpyxl/)[Python 请求教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/)
\ No newline at end of file
您可能也对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 集教程](/python/set/)[Python lambda 函数](/python/lambda/)[Python 列表推导](/articles/pythonlistcomprehensions/)[Python 映射教程](/python/map/)[Python 反向教程](/python/reverse/)[OpenPyXL 教程](/articles/openpyxl/)[Python Requests 教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/)
\ No newline at end of file
......@@ -180,4 +180,4 @@ y u o i e a
在本教程中,我们已经在 Python 中完成了反转操作。
您可能也对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 设置教程](/python/set/)[Python for 循环](/python/forloop/)[Python 列表推导](/articles/pythonlistcomprehensions/), 和 [Python 映射教程](/python/map/)
\ No newline at end of file
您可能也对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 集教程](/python/set/)[Python for 循环](/python/forloop/)[Python 列表推导](/articles/pythonlistcomprehensions/), 和 [Python 映射教程](/python/map/)
\ No newline at end of file
......@@ -205,4 +205,4 @@ btn1 = Button(self, text="Button 1",
在本教程中,我们使用了 Python lambda 函数。
您可能也对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 设置教程](/python/set/)[Python for 循环](/python/forloop/)[Python 列表推导](/articles/pythonlistcomprehensions/)[Python 映射教程](/python/map/)[OpenPyXL 教程](/articles/openpyxl/)[Python 请求教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/)
\ No newline at end of file
您可能也对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 集教程](/python/set/)[Python for 循环](/python/forloop/)[Python 列表推导](/articles/pythonlistcomprehensions/)[Python 映射教程](/python/map/)[OpenPyXL 教程](/articles/openpyxl/)[Python Requests 教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/)
\ No newline at end of file
# Python 集
# Python 集
> 原文: [http://zetcode.com/python/set/](http://zetcode.com/python/set/)
Python set 教程介绍了 Python set 集合。 我们展示了如何创建集合并对其执行操作。
Python `set`教程介绍了 Python `set`集合。 我们展示了如何创建集并对其执行操作。
## Python 集
## Python 集
Python 集是无序数据集合,没有重复的元素。 集合支持数学中已知的诸如并集,相交或求差的运算。
Python 集是无序数据集,没有重复的元素。 集支持数学中已知的诸如并集,相交或求差的运算。
## Python 集字面值
## Python 集字面值
从 Python 2.6 开始,可以使用字面值符号创建集合。 我们使用大括号在 Python 中定义一个集合,并且元素之间用逗号分隔。
从 Python 2.6 开始,可以使用字面值符号创建集。 我们使用大括号在 Python 中定义一个集,并且元素之间用逗号分隔。
`python_set_literal.py`
......@@ -31,7 +31,7 @@ nums = { 1, 2, 2, 2, 3, 4 }
```
合是唯一元素的集合; 即使我们提供了 3 次值 2,该集合也只包含一个 2。
是唯一元素的集; 即使我们提供了 3 次值 2,该集也只包含一个 2。
```py
$ ./python_set_literal.py
......@@ -42,9 +42,9 @@ $ ./python_set_literal.py
这是输出。
## Python 集函数
## Python 集函数
Python `set()`函数创建一个新集,其元素来自可迭代对象。 可迭代对象是我们可以迭代的对象; 例如字符串或列表。
Python `set()`函数创建一个新集,其元素来自可迭代对象。 可迭代对象是我们可以迭代的对象; 例如字符串或列表。
`python_set_fun.py`
......@@ -59,7 +59,7 @@ print(myset)
```
在示例中,我们使用`set()`内置函数从列表创建了一个集
在示例中,我们使用`set()`内置函数从列表创建了一个集。
```py
$ ./python_set_fun.py
......@@ -69,9 +69,9 @@ $ ./python_set_fun.py
这是输出。
## Python 集成员性测试
## Python 集成员性测试
`in``not in`运算符测试集中元素的存在。
`in``not in`运算符测试集中元素的存在。
`python_set_membership.py`
......@@ -96,7 +96,7 @@ else:
```
我们使用成员运算符检查集中是否存在两个单词。
我们使用成员运算符检查集中是否存在两个单词。
```py
$ ./python_set_membership.py
......@@ -107,7 +107,7 @@ tree is not present in the set
这是输出。
## Python 集内置函数
## Python 集内置函数
有几个内置 Python 函数,例如`len()``min()`,可以在 Python 集上使用。
......@@ -138,35 +138,35 @@ print("Number of elements: {0}".format(len(nums)))
```
`len()`方法返回集中的元素数。
`len()`方法返回集中的元素数。
```py
print("Minimum: {0}".format(min(nums)))
```
`min()`方法返回集中的最小值。
`min()`方法返回集中的最小值。
```py
print("Maximum: {0}".format(max(nums)))
```
`max()`方法返回集中的最大值。
`max()`方法返回集中的最大值。
```py
print("Sum: {0}".format(sum(nums)))
```
`sum()`方法返回集中值的总和。
`sum()`方法返回集中值的总和。
```py
print(sorted(nums))
```
最后,使用`sorted()`方法,我们可以从集中创建无序列表。
最后,使用`sorted()`方法,我们可以从集中创建无序列表。
```py
$ ./python_set_builtins.py
......@@ -182,9 +182,9 @@ Sorted elements:
这是输出。
## Python 集迭代
## Python 集迭代
可以使用 for 循环来迭代 Python 集。
可以使用`for`循环来迭代 Python 集。
`python_set_iteration.py`
......@@ -199,7 +199,7 @@ for word in words:
```
在示例中,我们遍历该集并逐个打印其元素。
在示例中,我们遍历该集并逐个打印其元素。
```py
$ ./python_set_iteration.py
......@@ -213,9 +213,9 @@ bottle
这是输出。
## Python 集添加
## Python 集添加
Python set `add()`方法将新元素添加到集中。
Python set `add()`方法将新元素添加到集中。
`python_set_add.py`
......@@ -240,9 +240,9 @@ $ ./python_set_add.py
这是输出。
## Python 集更新
## Python 集更新
Python set `update()`方法将一个或多个可迭代对象添加到集中。
Python set `update()`方法将一个或多个可迭代对象添加到集中。
`python_set_update.py`
......@@ -275,9 +275,9 @@ $ ./python_set_update.py
这是输出。
## Python 集删除
## Python 集删除
Python 有两种删除元素的基本方法:`remove()``discard()``remove()`方法从集合中删除指定的元素,如果元素不在集合中,则提高`KeyError``discard()`方法从集合中删除元素,如果要删除的元素不在集合中,则不执行任何操作。
Python 有两种删除元素的基本方法:`remove()``discard()``remove()`方法从集中删除指定的元素,如果元素不在集中,则提高`KeyError``discard()`方法从集中删除元素,如果要删除的元素不在集中,则不执行任何操作。
`python_set_remove.py`
......@@ -302,7 +302,7 @@ print(words)
```
在示例中,我们使用`remove()``discard()`删除集元素。
在示例中,我们使用`remove()``discard()`删除集元素。
```py
try:
......@@ -323,9 +323,9 @@ $ ./python_set_remove.py
这是输出。
## Python 集弹出&清除
## Python 集弹出&清除
`pop()`方法从集合中移除并返回任意元素。 `clear()`方法从集合中删除所有元素。
`pop()`方法从集中移除并返回任意元素。 `clear()`方法从集中删除所有元素。
`python_set_remove2.py`
......@@ -345,7 +345,7 @@ print(words)
```
在示例中,我们删除并打印两个随机元素,并显示其余元素。 然后,使用`clear()`从集中删除所有元素。
在示例中,我们删除并打印两个随机元素,并显示其余元素。 然后,使用`clear()`从集中删除所有元素。
```py
$ ./python_set_remove2.py
......@@ -358,7 +358,7 @@ set()
这是输出。
## Python 集运算
## Python 集运算
使用 Python 集,我们可以执行特定的运算:并集,交集,差和对称差。
......@@ -393,7 +393,7 @@ print("union:", set1.union(set2))
```
`union()`方法执行联合操作,该操作返回两个集中的所有元素。
`union()`方法执行联合操作,该操作返回两个集中的所有元素。
```py
print("difference:", set1.difference(set2))
......@@ -441,11 +441,11 @@ print("symmetric difference:", set1 ^ set2)
```
该示例显示了使用运算符的四个 set 操作。
该示例显示了使用运算符的四个`set`操作。
## 子集和超集
如果集合 A 的所有元素都包含在集合 B 中,则将 A 称为 B 的子集,将 B 称为 A 的超集。
如果集 A 的所有元素都包含在集 B 中,则将 A 称为 B 的子集,将 B 称为 A 的超集。
`python_subset_superset.py`
......@@ -520,6 +520,6 @@ AttributeError: 'frozenset' object has no attribute 'add'
当我们尝试向冻结集中添加新元素时出现错误。
在本教程中,我们使用了 Python set 集合
在本教程中,我们使用了 Python `set`
您可能也对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python lambda 函数](/python/lambda/)[Python for 循环](/python/forloop/)[Python 列表推导](/articles/pythonlistcomprehensions/)[Python 映射教程](/python/map/)[OpenPyXL 教程](/articles/openpyxl/)[Python 请求教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/)
\ No newline at end of file
您可能也对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python lambda 函数](/python/lambda/)[Python `for`循环](/python/forloop/)[Python 列表推导](/articles/pythonlistcomprehensions/)[Python 映射教程](/python/map/)[OpenPyXL 教程](/articles/openpyxl/)[Python Requests 教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/)
\ No newline at end of file
......@@ -70,7 +70,7 @@ for num in nums_squared:
```
我们遍历返回的 iterable 并打印元素。
我们遍历返回的`iterable`并打印元素。
```py
$ ./python_map.py
......@@ -216,7 +216,7 @@ for i in nums:
```
我们遍历 for 循环中的元素。 在每个循环中,我们创建两个值的列表,这些值是通过对值应用`add()``square()`函数来计算的。
我们遍历`for`循环中的元素。 在每个循环中,我们创建两个值的列表,这些值是通过对值应用`add()``square()`函数来计算的。
```py
$ ./python_map_multiple_funcs.py
......@@ -257,4 +257,4 @@ for num in nums_squared:
在本教程中,我们使用了 Python `map()`函数。
您可能也会对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 设置教程](/python/set/)[Python 列表推导](/articles/pythonlistcomprehensions/)[OpenPyXL 教程](/articles/openpyxl/)[ [Python 请求教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/)
\ No newline at end of file
您可能也会对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 集教程](/python/set/)[Python 列表推导](/articles/pythonlistcomprehensions/)[OpenPyXL 教程](/articles/openpyxl/)[Python Requests 教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/)
\ No newline at end of file
......@@ -82,7 +82,7 @@ for row in reader:
```
通过两个 for 循环,我们遍历数据。
通过两个`for`循环,我们遍历数据。
```py
$ ./read_csv.py
......@@ -132,7 +132,7 @@ with f:
```
该代码示例从使用'|'的 CSV 文件读取并显示数据。 定界符
该代码示例从使用`'|'`定界符的 CSV 文件读取并显示数据
```py
$ ./read_csv2.py
......@@ -193,7 +193,7 @@ for row in reader:
## Python CSV 编写器
`csv.writer()`方法返回一个 writer 对象,该对象将用户数据转换为给定文件状对象上的定界字符串。
`csv.writer()`方法返回一个`writer`对象,该对象将用户数据转换为给定文件状对象上的定界字符串。
`write_csv.py`
......@@ -345,4 +345,4 @@ cups#1
在本教程中,我们使用 Python 处理 CSV。
您可能也会对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 列表推导式](/articles/pythonlistcomprehensions/)[PrettyTable 教程](/python/prettytable/)[PyMongo 教程](/python/pymongo/)[Python simplejson 教程](/python/simplejson/)[OpenPyXL 教程](/articles/openpyxl/)[Python 请求教程](/web/pythonrequests/)[Python 列表推导](/articles/pythonlistcomprehensions/)
\ No newline at end of file
您可能也会对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 列表推导式](/articles/pythonlistcomprehensions/)[PrettyTable 教程](/python/prettytable/)[PyMongo 教程](/python/pymongo/)[Python simplejson 教程](/python/simplejson/)[OpenPyXL 教程](/articles/openpyxl/)[Python Requests 教程](/web/pythonrequests/)[Python 列表推导](/articles/pythonlistcomprehensions/)
\ No newline at end of file
......@@ -2,15 +2,15 @@
> 原文: [http://zetcode.com/python/regularexpressions/](http://zetcode.com/python/regularexpressions/)
Python 正则表达式教程展示了如何在 Python 中使用正则表达式。 对于 Python 中的正则表达式,我们使用 re 模块。
Python 正则表达式教程展示了如何在 Python 中使用正则表达式。 对于 Python 中的正则表达式,我们使用`re`模块。
正则表达式用于文本搜索和更高级的文本操作。 正则表达式是内置工具,如 grep,sed,文本编辑器(如 vi,emacs),编程语言(如 Tcl,Perl 和 Python)。
正则表达式用于文本搜索和更高级的文本操作。 正则表达式是内置工具,如`grep``sed`,文本编辑器(如 vi,emacs),编程语言(如 Tcl,Perl 和 Python)。
## Python `re`模块
在 Python 中,`re`模块提供了正则表达式匹配操作。
模式是一个正则表达式,用于定义我们正在搜索或操纵的文本。 它由文本文字和元字符组成。 用`compile()`函数编译该模式。 由于正则表达式通常包含特殊字符,因此建议使用原始字符串。 (原始字符串以 r 字符开头。)这样,在将字符编译为模式之前,不会对这些字符进行解释。
模式是一个正则表达式,用于定义我们正在搜索或操纵的文本。 它由文本文字和元字符组成。 用`compile()`函数编译该模式。 由于正则表达式通常包含特殊字符,因此建议使用原始字符串。 (原始字符串以`r`字符开头。)这样,在将字符编译为模式之前,不会对这些字符进行解释。
编译模式后,可以使用其中一个函数将模式应用于文本字符串。 函数包括`match()``search()``find()``finditer()`
......@@ -25,9 +25,9 @@ Python 正则表达式教程展示了如何在 Python 中使用正则表达式
| `^` | 匹配字符串中的起始位置。 |
| `$` | 匹配字符串中的结束位置。 |
| <code>&#124;</code> | 备用运算符。 |
| `[abc]` | 匹配 a 或 b 或 c。 |
| `[a-c]` | 范围; 匹配 a 或 b 或 c。 |
| `[^abc]` | 否定,匹配除 a 或 b 或 c 之外的所有内容。 |
| `[abc]` | 匹配`a``b``c`。 |
| `[a-c]` | 范围; 匹配`a``b``c`。 |
| `[^abc]` | 否定,匹配除`a``b``c`之外的所有内容。 |
| `\s` | 匹配空白字符。 |
| `\w` | 匹配单词字符; 等同于`[a-zA-Z_0-9]` |
......@@ -53,14 +53,14 @@ for word in words:
```
在示例中,我们有一个单词元组。 编译后的模式将在每个单词中寻找一个“ book”字符串。
在示例中,我们有一个单词元组。 编译后的模式将在每个单词中寻找一个“`book`”字符串。
```py
pattern = re.compile(r'book')
```
使用`compile()`函数,我们可以创建图案。 正则表达式是一个原始字符串,由四个普通字符组成。
使用`compile()`函数,我们可以创建模式串。 正则表达式是一个原始字符串,由四个普通字符组成。
```py
for word in words:
......@@ -80,7 +80,7 @@ The bookstore matches
```
元组中的四个单词与模式匹配。 请注意,以“ book”一词开头的单词不匹配。 为了包括这些词,我们使用`search()`函数。
元组中的四个单词与模式匹配。 请注意,以“`book`”一词开头的单词不匹配。 为了包括这些词,我们使用`search()`函数。
## 搜索函数
......@@ -104,7 +104,7 @@ for word in words:
```
在示例中,我们使用`search()`函数查找“ book”一词。
在示例中,我们使用`search()`函数查找“`book`”一词。
```py
$ ./search_fun.py
......@@ -217,7 +217,7 @@ for sentence in sentences:
```
在示例中,我们有三个句子。 搜索模式为`^Jane`。 该模式检查“ Jane”字符串是否位于文本的开头。 `Jane\.`将在句子结尾处查找“ Jane”。
在示例中,我们有三个句子。 搜索模式为`^Jane`。 该模式检查“`Jane`”字符串是否位于文本的开头。 `Jane\.`将在句子结尾处查找“`Jane`”。
## `fullmatch`
......@@ -241,7 +241,7 @@ for word in words:
```
在示例中,我们寻找与“ book”一词完全匹配的内容。
在示例中,我们寻找与“`book`”一词完全匹配的内容。
```py
$ ./exact_match.py
......@@ -390,7 +390,7 @@ pattern = re.compile(r'Jane|Beky|Robert')
```
此正则表达式查找“​​ Jane”,“ Beky”或“ Robert”字符串。
此正则表达式查找“​​`Jane`”,“`Beky`”或“`Robert`”字符串。
## 查找方法
......@@ -417,7 +417,7 @@ for item in found:
```
在示例中,我们在文本中搜索“ fox”一词。 我们遍历找到的匹配项的迭代器,并使用它们的索引进行打印。
在示例中,我们在文本中搜索“`fox`”一词。 我们遍历找到的匹配项的迭代器,并使用它们的索引进行打印。
```py
s = item.start()
......@@ -438,7 +438,7 @@ Found fox at 29:32
## 捕获组
捕获组是一种将多个字符视为一个单元的方法。 通过将字符放置在一组圆括号内来创建它们。 例如,(book)是包含'b','o','o','k',字符的单个组。
捕获组是一种将多个字符视为一个单元的方法。 通过将字符放置在一组圆括号内来创建它们。 例如,`(book)`是包含`'b', 'o', 'o', 'k'`字符的单个组。
捕获组技术使我们能够找出字符串中与常规模式匹配的那些部分。
......@@ -518,7 +518,7 @@ pattern = re.compile(r'^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,18}$')
第四部分是点字符。 它前面带有转义字符(\),以获取文字点。
最后一部分是顶级域:`[a-zA-Z.]{2,18}`。 顶级域可以包含 2 到 18 个字符,例如 sk,net,信息,旅行,清洁,旅行保险。 最大长度可以为 63 个字符,但是今天大多数域都少于 18 个字符。 还有一个点字符。 这是因为某些顶级域包含两个部分: 例如 co.uk
最后一部分是顶级域:`[a-zA-Z.]{2,18}`。 顶级域可以包含 2 到 18 个字符,例如`sk, net, info, travel, cleaning, travelinsurance`。 最大长度可以为 63 个字符,但是今天大多数域都少于 18 个字符。 还有一个点字符。 这是因为某些顶级域包含两个部分: 例如`co.uk`
```py
$ ./emails.py
......
# Python simplejson 教程
# Python SimpleJson 教程
> 原文: [http://zetcode.com/python/simplejson/](http://zetcode.com/python/simplejson/)
Python simplejson 教程展示了如何使用 Python simplejson 模块读取和写入 JSON 数据。
Python SimpleJson 教程展示了如何使用 Python SimpleJson 模块读取和写入 JSON 数据。
## JSON 格式
JSON(JavaScript 对象表示法)是一种轻量级的数据交换格式。 它很容易被人读写,也可以由机器解析和生成。 `application/json`是 JSON 的官方 Internet 媒体类型。 JSON 文件扩展名是`.json`
JSON(JavaScript 对象表示法)是一种轻量级的数据交换格式。 它很容易被人读写,也可以由机器解析和生成。 `application/json`是 JSON 的官方互联网媒体类型。 JSON 文件扩展名是`.json`
## simplejson 模块
## SimpleJson 模块
simplejson 是适用于 Python 2.5+和 Python 3.3+的简单,快速,完整且可扩展的 JSON 编码器和解码器。 它是没有依赖性的纯 Python 代码。
SimpleJson 是适用于 Python 2.5+和 Python 3.3+的简单,快速,完整且可扩展的 JSON 编码器和解码器。 它是没有依赖性的纯 Python 代码。
`simplejson`模块包含在现代 Python 版本中。 解码器可以处理任何指定编码的传入 JSON 字符串(默认为 UTF-8)
SimpleJson 模块包含在现代 Python 版本中。 解码器可以处理任何指定编码的传入 JSON 字符串(默认为 UTF-8)
## 使用 simplejson
## 使用 SimpleJson
```py
import json
```
要使用`simplejson`模块,我们导入`json`
要使用 SimpleJson 模块,我们导入`json`
## Simplejson 转换表
## SimpleJson 转换表
下表显示了如何在 Python 和 JSON 之间转换数据类型。
......@@ -174,7 +174,7 @@ $ ./simple.py
这是示例的输出。
## Simplejson 从 URL 读取 JSON
## SimpleJson 从 URL 读取 JSON
以下示例从网页读取 JSON 数据。 我们从`http://time.jsontest.com`获得 JSON 数据。
......@@ -236,9 +236,9 @@ Date: 06-01-2017
这是输出。
## 漂亮地打印
## 精美打印
使用 simplejson,我们可以轻松漂亮地打印数据。
使用 SimpleJson,我们可以轻松精美打印数据。
`pretty_print_json.py`
......@@ -275,9 +275,9 @@ $ ./pretty_print_json.py
这是示例的输出。 数据缩进并对键进行排序。
## Simplejson 自定义类
## SimpleJson 自定义类
Simplejson 仅序列化和反序列化一些 Python 对象,这些对象在转换表中列出。 对于自定义 Python 对象,我们需要执行一些附加步骤。
SimpleJson 仅序列化和反序列化一些 Python 对象,这些对象在转换表中列出。 对于自定义 Python 对象,我们需要执行一些附加步骤。
`custom_class.py`
......@@ -318,7 +318,7 @@ $ ./custom_class.py
这是输出。
## 自定义类的 Simplejson 列表
## 自定义类的 SimpleJson 列表
在下一个示例中,我们显示如何序列化自定义类的列表。
......@@ -375,6 +375,6 @@ $ ./custom_class_list.py
这是示例的输出。
在本教程中,我们使用了 Python simplejson 库。
在本教程中,我们使用了 Python SimpleJson 库。
您可能也会对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 列表推导式](/articles/pythonlistcomprehensions/)[Pyquery 教程](/python/pyquery)[OpenPyXL 教程](/articles/openpyxl/)[HTG8 Python 请求教程和 [Python CSV 教程](/python/csv/)
\ No newline at end of file
您可能也会对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 列表推导式](/articles/pythonlistcomprehensions/)[Pyquery 教程](/python/pyquery)[OpenPyXL 教程](/articles/openpyxl/)[Python Requests 教程和 [Python CSV 教程](/python/csv/)
\ No newline at end of file
......@@ -2,7 +2,7 @@
> 原文: [http://zetcode.com/python/sympy/](http://zetcode.com/python/sympy/)
SymPy 教程展示了如何使用 sympy 模块在 Python 中进行符号计算。 这是对 SymPy 的简要介绍。
SymPy 教程展示了如何使用`sympy`模块在 Python 中进行符号计算。 这是对 SymPy 的简要介绍。
计算机代数系统(CAS)是一种数学软件,能够以类似于数学家和科学家的传统手动计算方式来处理数学表达式。
......@@ -21,7 +21,7 @@ SymPy 是使用`pip install sympy`命令安装的。
## `Rational`值
SymPy 具有用于处理有理数的`Rational`。 有理数是可以表示为两个整数(分子 p 和非零分母 q)的商或分数 p / q 的任何数字。
SymPy 具有用于处理有理数的`Rational`。 有理数是可以表示为两个整数(分子`p`和非零分母`q`)的商或分数`p / q`的任何数字。
`rational_values.py`
......@@ -63,7 +63,7 @@ $ rational_values.py
## SymPy `pprint`
`pprint()`用于在控制台上漂亮地打印输出。 LaTeX 可以达到最佳效果,例如 在 Jupyter 笔记本中。
`pprint()`用于在控制台上精美打印输出。 LaTeX 可以达到最佳效果,例如 在 Jupyter 笔记本中。
`prettify.py`
......@@ -364,7 +364,7 @@ print(pi.evalf(30))
```
该示例将 pi 值求值为 30 个位。
该示例将`pi`值求值为 30 个位。
```py
$ evaluating.py
......@@ -562,7 +562,7 @@ print(l1)
```
我们计算`1/x`的极限,其中 x 接近正无穷大。
我们计算`1/x`的极限,其中`x`接近正无穷大。
```py
$ limit.py
......
......@@ -2,7 +2,7 @@
> 原文: [http://zetcode.com/python/pandas/](http://zetcode.com/python/pandas/)
这是熊猫的入门教程。 本教程展示了如何使用 Pandas 库在 Python 中进行基本数据分析。 代码示例和数据可在作者的 Github [存储](https://github.com/janbodnar/Python-Course/tree/master/datascience/pandas)中获得。
这是Pandas的入门教程。 本教程展示了如何使用 Pandas 库在 Python 中进行基本数据分析。 代码示例和数据可在作者的 Github [](https://github.com/janbodnar/Python-Course/tree/master/datascience/pandas)中获得。
## Pandas
......@@ -57,7 +57,7 @@ import pandas as pd
```
我们导入熊猫库。
我们导入Pandas库。
```py
data = [['Alex', 10], ['Ronald', 18], ['Jane', 33]]
......@@ -146,7 +146,7 @@ dtype: int64
左列是索引。
## Pandas 序列 ndarray
## Pandas 序列`ndarray`
我们可以从 numpy `ndarray` 创建一个系列对象。
......@@ -325,7 +325,7 @@ SA South Africa Pretoria 1.221 52.98
## Pandas 索引、列和值
熊猫`DataFrame`具有三个基本部分:索引,列和值。
Pandas`DataFrame`具有三个基本部分:索引,列和值。
`index_vals_cols.py`
......@@ -447,7 +447,7 @@ print(df.to_string(index=False))
```
由于我们有 positions 列,因此我们从输出中隐藏索引。
由于我们有`positions`列,因此我们从输出中隐藏索引。
```py
$ python read_from_csv.py
......@@ -598,7 +598,7 @@ max 8.00000 61.000000
## Pandas 计数
下一个示例对值进行计数。 您可以在 Github 存储库中找到`employees.csv`文件。
下一个示例对值进行计数。 您可以在 Github 库中找到`employees.csv`文件。
`counting.py`
......@@ -706,7 +706,7 @@ $ python no_header.py
```
这是输出。 (值 1 到 4 来自 pos 列。)
这是输出。 (值 1 到 4 来自`pos`列。)
## Pandas `loc()`
......@@ -745,7 +745,7 @@ print(df.loc[['A', 'B'], ['Items']])
```
在这里,我们获得了 Items 列的前两行。
在这里,我们获得了`Items`列的前两行。
```py
$ python select_loc.py
......@@ -935,4 +935,4 @@ $ python sorting2.py
在本教程中,我们使用了 Pandas 库。
您可能也对以下相关教程感兴趣: [Python 教程](/lang/python/)[OpenPyXL 教程](/articles/openpyxl/)[Python 请求教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/), 或列出[所有 Python 教程](/all/#python)
\ No newline at end of file
您可能也对以下相关教程感兴趣: [Python 教程](/lang/python/)[OpenPyXL 教程](/articles/openpyxl/)[Python Requests 教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/), 或列出[所有 Python 教程](/all/#python)
\ No newline at end of file
......@@ -2,7 +2,7 @@
> 原文: [http://zetcode.com/python/pillow/](http://zetcode.com/python/pillow/)
Pillow 教程展示了如何在 Python 中使用 Pillow 来处理图像。 来源可从作者的 Github [存储](https://github.com/janbodnar/pillow-examples)中获得。
Pillow 教程展示了如何在 Python 中使用 Pillow 来处理图像。 来源可从作者的 Github [](https://github.com/janbodnar/pillow-examples)中获得。
## Pillow
......@@ -38,7 +38,7 @@ from PIL import Image
```
PIL 模块中,我们包含`Image`类。
`PIL`模块中,我们包含`Image`类。
```py
tatras = Image.open("tatras.jpg")
......@@ -209,7 +209,7 @@ grayscale = tatras.convert('L')
```
`convert()`方法的第一个参数是 mode; “ L”模式是黑白的。
`convert()`方法的第一个参数是`mode``"L"`模式是黑白的。
## 用 Pillow 裁剪图像
......@@ -458,7 +458,7 @@ img = Image.new('RGBA', (200, 200), 'white')
```
创建一个新的`Image`。 图像模式为“ RGBA”。 尺寸为 200x200,背景为白色。
创建一个新的`Image`。 图像模式为“`RGBA`”。 尺寸为`200x200`,背景为白色。
```py
idraw = ImageDraw.Draw(img)
......
......@@ -123,7 +123,7 @@ $ ./listing.py
## FTP 命令
FTP 客户端将命令发送到 FTP 服务器,例如`PWD``RETR`ftplib 包含几种包装这些命令的方法。 使用`sendcmd()``voidcmd()`方法发送命令。
FTP 客户端将命令发送到 FTP 服务器,例如`PWD``RETR``ftplib`包含几种包装这些命令的方法。 使用`sendcmd()``voidcmd()`方法发送命令。
`ftp_commands.py`
......@@ -315,7 +315,7 @@ with ftplib.FTP('ftp.debian.org') as ftp:
```
该示例使用`size()`方法检索 README 文件的大小。
该示例使用`size()`方法检索`README`文件的大小。
## 获取二进制文件的大小
......@@ -455,4 +455,4 @@ with ftplib.FTP('ftp.example.com') as ftp:
在本教程中,我们使用了 Python `ftplib`
您可能也对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 设置教程](/python/set/)[Python lambda 函数](/python/lambda/)[Python 列表推导](/articles/pythonlistcomprehensions/)[Python 映射教程](/python/map/)[OpenPyXL 教程](/articles/openpyxl/)[Python 请求教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/)
\ No newline at end of file
您可能也对以下相关教程感兴趣: [Python 教程](/lang/python/)[Python 集教程](/python/set/)[Python lambda 函数](/python/lambda/)[Python 列表推导](/articles/pythonlistcomprehensions/)[Python 映射教程](/python/map/)[OpenPyXL 教程](/articles/openpyxl/)[Python Requests 教程](/web/pythonrequests/)[Python CSV 教程](/python/csv/)
\ No newline at end of file
......@@ -375,4 +375,4 @@ in 4 hours
在本教程中,我们使用带有箭头模块的 Python 中的日期和时间。
您可能也对以下相关教程感兴趣: [Beautifulsoup 教程](/python/beautifulsoup)[Python 教程](/lang/python/)[Python 列表推导式](/articles/pythonlistcomprehensions/)[OpenPyXL 教程](/articles/openpyxl/)[HTG8 Python 请求教程和 [Python CSV 教程](/python/csv/)
\ No newline at end of file
您可能也对以下相关教程感兴趣: [Beautifulsoup 教程](/python/beautifulsoup)[Python 教程](/lang/python/)[Python 列表推导式](/articles/pythonlistcomprehensions/)[OpenPyXL 教程](/articles/openpyxl/)[HTG8 Python Requests 教程和 [Python CSV 教程](/python/csv/)
\ No newline at end of file
......@@ -2,7 +2,7 @@
> 原文: [http://zetcode.com/pyqt/qpropertyanimation/](http://zetcode.com/pyqt/qpropertyanimation/)
PyQt 中的 QPropertyAnimation 显示了如何使用`QPropertyAnimation`在 PyQt 中创建动画。 在示例中,我们对对象的大小,颜色和位置进行了动画处理。 来源和球图像可以在作者的 Github [存储](https://github.com/janbodnar/pyqt-qpropertyanimation)中找到。
PyQt 中的 QPropertyAnimation 显示了如何使用`QPropertyAnimation`在 PyQt 中创建动画。 在示例中,我们对对象的大小,颜色和位置进行了动画处理。 来源和球图像可以在作者的 Github [](https://github.com/janbodnar/pyqt-qpropertyanimation)中找到。
## `QPropertyAnimation`
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册