Glossary - 术语对照表 2

本文深入解析Python编程中的关键术语,如二进制文件、字节类对象、字节码、类、类变量、强制类型转换、复数、上下文管理器、上下文变量、连续等概念,为Python学习者提供全面的词汇理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Glossary - 术语对照表 2

Glossary
https://docs.python.org/3.7/glossary.html

术语对照表
https://docs.python.org/zh-cn/3.7/glossary.html

1. binary file - 二进制文件

A file object able to read and write bytes-like objects. Examples of binary files are files opened in binary mode (‘rb’, ‘wb’ or ‘rb+’), sys.stdin.buffer, sys.stdout.buffer, and instances of io.BytesIO and gzip.GzipFile.
file object 能够读写字节类对象。二进制文件的例子包括以二进制模式 (‘rb’, ‘wb’ or ‘rb+’) 打开的文件、sys.stdin.buffer、sys.stdout.buffer 以及 io.BytesIO 和 gzip.GzipFile 的实例。

See also text file for a file object able to read and write str objects.
另请参见 text file 了解能够读写 str 对象的文件对象。

2. bytes-like object - 字节类对象

An object that supports the Buffer Protocol and can export a C-contiguous buffer. This includes all bytes, bytearray, and array.array objects, as well as many common memoryview objects. Bytes-like objects can be used for various operations that work with binary data; these include compression, saving to a binary file, and sending over a socket.
支持缓冲协议并且能导出 C-contiguous 缓冲的对象。这包括所有 bytes、bytearray 和 array.array 对象,以及许多普通 memoryview 对象。字节类对象可在多种二进制数据操作中使用;这些操作包括压缩、保存为二进制文件以及通过套接字发送等。

Some operations need the binary data to be mutable. The documentation often refers to these as “read-write bytes-like objects”. Example mutable buffer objects include bytearray and a memoryview of a bytearray. Other operations require the binary data to be stored in immutable objects (“read-only bytes-like objects”); examples of these include bytes and a memoryview of a bytes object.
某些操作需要可变的二进制数据。这种对象在文档中常被称为“可读写字节类对象”。可变缓冲对象的例子包括 bytearray 以及 bytearray 的 memoryview。其他操作要求二进制数据存放于不可变对象 (只读字节类对象);这种对象的例子包括 bytes 以及 bytes 对象的 memoryview。

3. bytecode - 字节码

Python source code is compiled into bytecode, the internal representation of a Python program in the CPython interpreter. The bytecode is also cached in .pyc files so that executing the same file is faster the second time (recompilation from source to bytecode can be avoided). This “intermediate language” is said to run on a virtual machine that executes the machine code corresponding to each bytecode. Do note that bytecodes are not expected to work between different Python virtual machines, nor to be stable between Python releases.
Python 源代码会被编译为字节码,即 CPython 解释器中表示 Python 程序的内部代码。字节码还会缓存在 .pyc 文件中,这样第二次执行同一文件时速度更快 (可以免去将源码重新编译为字节码)。这种中间语言运行在根据字节码执行相应机器码的 virtual machine 之上。请注意不同 Python 虚拟机上的字节码不一定通用,也不一定能在不同 Python 版本上兼容。

A list of bytecode instructions can be found in the documentation for the dis module.
字节码指令列表可以在 dis 模块的文档中查看。

4. class - 类

A template for creating user-defined objects. Class definitions normally contain method definitions which operate on instances of the class.
用来创建用户定义对象的模板。类定义通常包含对该类的实例进行操作的方法定义。

5. class variable - 类变量

A variable defined in a class and intended to be modified only at class level (i.e., not in an instance of the class).
在类中定义的变量,并且仅限在类的层级上修改 (而不是在类的实例中修改)。

6. coercion - 强制类型转换

The implicit conversion of an instance of one type to another during an operation which involves two arguments of the same type. For example, int(3.15) converts the floating point number to the integer 3, but in 3+4.5, each argument is of a different type (one int, one float), and both must be converted to the same type before they can be added or it will raise a TypeError. Without coercion, all arguments of even compatible types would have to be normalized to the same value by the programmer, e.g., float(3)+4.5 rather than just 3+4.5.
在包含两个相同类型参数的操作中,一种类型的实例隐式地转换为另一种类型。例如,int(3.15) 是将原浮点数转换为整型数 3,但在 3+4.5 中,参数的类型不一致 (一个是 int, 一个是 float),两者必须转换为相同类型才能相加,否则将引发 TypeError。如果没有强制类型转换机制,程序员必须将所有可兼容参数归一化为相同类型,例如要写成 float(3)+4.5 而不是 3+4.5。

7. complex number - 复数

An extension of the familiar real number system in which all numbers are expressed as a sum of a real part and an imaginary part. Imaginary numbers are real multiples of the imaginary unit (the square root of -1), often written i in mathematics or j in engineering. Python has built-in support for complex numbers, which are written with this latter notation; the imaginary part is written with a j suffix, e.g., 3+1j. To get access to complex equivalents of the math module, use cmath. Use of complex numbers is a fairly advanced mathematical feature. If you’re not aware of a need for them, it’s almost certain you can safely ignore them.
对普通实数系统的扩展,其中所有数字都被表示为一个实部和一个虚部的和。虚数是虚数单位 (-1 的平方根) 的实倍数,通常在数学中写为 i,在工程学中写为 j。Python 内置了对复数的支持,采用工程学标记方式;虚部带有一个 j 后缀,例如 3+1j。如果需要 math 模块内对象的对应复数版本,请使用 cmath,复数的使用是一个比较高级的数学特性。如果你感觉没有必要,忽略它们也几乎不会有任何问题。

8. context manager - 上下文管理器

An object which controls the environment seen in a with statement by defining __enter__() and __exit__() methods. See PEP 343.
在 with 语句中使用,通过定义 __enter__()__exit__() 方法来控制环境状态的对象。参见 PEP 343。

9. context variable - 上下文变量

A variable which can have different values depending on its context. This is similar to Thread-Local Storage in which each execution thread may have a different value for a variable. However, with context variables, there may be several contexts in one execution thread and the main usage for context variables is to keep track of variables in concurrent asynchronous tasks. See contextvars.
一种根据其所属的上下文可以具有不同的值的变量。这类似于在线程局部存储中每个执行线程可以具有不同的变量值。不过,对于上下文变量来说,一个执行线程中可能会有多个上下文,而上下文变量的主要用途是对并发异步任务中变量进行追踪。参见 contextvars。

10. contiguous - 连续

A buffer is considered contiguous exactly if it is either C-contiguous or Fortran contiguous. Zero-dimensional buffers are C and Fortran contiguous. In one-dimensional arrays, the items must be laid out in memory next to each other, in order of increasing indexes starting from zero. In multidimensional C-contiguous arrays, the last index varies the fastest when visiting items in order of memory address. However, in Fortran contiguous arrays, the first index varies the fastest.
一个缓冲如果是 C 连续或 Fortran 连续就会被认为是连续的。零维缓冲是 C 和 Fortran 连续的。在一维数组中,所有条目必须在内存中彼此相邻地排列,采用从零开始的递增索引顺序。在多维 C-连续数组中,当按内存地址排列时用最后一个索引访问条目时速度最快。但是在 Fortran 连续数组中则是用第一个索引最快。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值