rafaym's picture
Initial upload — Legesher native code submission portal
0807ad2 verified
# Chinese (中文) - Python Quick Reference
![Legesher](https://img.shields.io/badge/Legesher-zh-blue?style=for-the-badge&logo=python&logoColor=white)
![Script](https://img.shields.io/badge/Script-Simplified%20Chinese%20%28Han%29-green?style=for-the-badge)
![Status](https://img.shields.io/badge/Status-Experimental-yellow?style=for-the-badge)
> Write Python code in Chinese. This guide shows the Chinese keywords
> to use for Legesher to understand your code.
## Language Details
| Attribute | Value |
| --------- | ----- |
| **Language** | Chinese |
| **Native Name** | 中文 |
| **Script** | Simplified Chinese (Han) |
| **ISO 639-1** | `zh` |
| **ISO 639-2** | `zho` |
| **BCP 47 Tag** | `zh-Hans` |
| **Text Direction** | Left-to-Right (LTR) |
| **Status** | Experimental |
## Keywords (39 terms)
These are Python's reserved words translated to Chinese.
| English | Chinese |
| ------- | ------ |
| `and` | `和` |
| `as` | `作为` |
| `assert` | `断言` |
| `async` | `异步` |
| `await` | `等待` |
| `break` | `终止` |
| `case` | `情况` |
| `class` | `类` |
| `continue` | `继续` |
| `def` | `定义` |
| `del` | `删除` |
| `elif` | `否则如果` |
| `else` | `否则` |
| `except` | `除外` |
| `except*` | `多重捕获*` |
| `False` | `错误` |
| `finally` | `最后` |
| `for` | `对于` |
| `from` | `从` |
| `global` | `全球` |
| `if` | `如果` |
| `import` | `导入` |
| `in` | `在` |
| `is` | `是` |
| `lambda` | `拉姆达` |
| `match` | `匹配` |
| `None` | `无` |
| `nonlocal` | `非本地` |
| `not` | `不` |
| `or` | `或` |
| `pass` | `过` |
| `raise` | `提出` |
| `return` | `返回` |
| `True` | `真实` |
| `try` | `尝试` |
| `type` | `类型` |
| `while` | `当` |
| `with` | `跟` |
| `yield` | `产生` |
## Built-in Functions (72 terms)
Python's built-in functions and types in Chinese.
| English | Chinese |
| ------- | ------ |
| `abs` | `绝对值` |
| `aiter` | `异步迭代器` |
| `all` | `全` |
| `anext` | `下一项` |
| `any` | `任意` |
| `ascii` | `ASCII` |
| `bin` | `二进制` |
| `bool` | `布尔` |
| `breakpoint` | `断点` |
| `bytearray` | `字节数组` |
| `bytes` | `字节` |
| `callable` | `可调用` |
| `chr` | `字符` |
| `classmethod` | `类方法` |
| `compile` | `编译` |
| `complex` | `复数` |
| `delattr` | `删除属性` |
| `dict` | `字典` |
| `dir` | `列出属性和方法` |
| `divmod` | `除模` |
| `ellipsis` | `省略号` |
| `enumerate` | `枚举` |
| `eval` | `评估` |
| `exec` | `执行` |
| `filter` | `过滤` |
| `float` | `浮点数` |
| `format` | `格式化` |
| `frozenset` | `冻结集` |
| `getattr` | `获取属性` |
| `globals` | `全局变量` |
| `hasattr` | `具有` |
| `hash` | `哈希` |
| `help` | `帮助` |
| `hex` | `十六进制` |
| `id` | `标识` |
| `input` | `输入` |
| `int` | `整数` |
| `isinstance` | `是实例` |
| `issubclass` | `是子类` |
| `iter` | `迭代` |
| `len` | `长度` |
| `list` | `列表` |
| `locals` | `局部变量` |
| `map` | `映射` |
| `max` | `最大值` |
| `memoryview` | `内存视图` |
| `min` | `最小值` |
| `next` | `下一个` |
| `notimplemented` | `未实现` |
| `object` | `对象` |
| `oct` | `八进制` |
| `open` | `打开` |
| `ord` | `顺序` |
| `pow` | `幂` |
| `print` | `打印` |
| `property` | `属性` |
| `range` | `范围` |
| `repr` | `表示` |
| `reversed` | `反转` |
| `round` | `四舍五入` |
| `set` | `集合` |
| `setattr` | `设置属性` |
| `slice` | `切片` |
| `sorted` | `排序` |
| `staticmethod` | `静态方法` |
| `str` | `字符串` |
| `sum` | `求和` |
| `super` | `超类` |
| `tuple` | `元组` |
| `type` | `类型` |
| `vars` | `变量字典` |
| `zip` | `压缩` |
## Exceptions (69 terms)
Exception classes for error handling.
| English | Chinese |
| ------- | ------ |
| `arithmeticerror` | `算术错误` |
| `assertionerror` | `断言错误` |
| `attributeerror` | `属性错误` |
| `baseexception` | `基本异常` |
| `baseexceptiongroup` | `基异常组` |
| `basegeneratorexit` | `基底生成器退出` |
| `blockingioerror` | `阻塞的IO错误` |
| `brokenpipeerror` | `破管错误` |
| `buffererror` | `缓冲区错误` |
| `byteswarning` | `字节警告` |
| `childprocesserror` | `子进程错误` |
| `connectionabortederror` | `连接中断错误` |
| `connectionerror` | `连接错误` |
| `connectionrefusederror` | `连接拒绝错误` |
| `connectionreseterror` | `连接重置错误` |
| `deprecationwarning` | `弃用警告` |
| `encodingwarning` | `编码警告` |
| `environmenterror` | `环境错误` |
| `eoferror` | `文件结束错误` |
| `exception` | `异常` |
| `exceptiongroup` | `异常组` |
| `fileexistserror` | `文件已存在错误` |
| `filenotfounderror` | `文件未找到错误` |
| `floatingpointerror` | `浮点数错误` |
| `futurewarning` | `未来警告` |
| `generatorexit` | `生成器退出` |
| `importerror` | `导入错误` |
| `importwarning` | `导入警告` |
| `indentationerror` | `缩进错误` |
| `indexerror` | `越界访问错误` |
| `interruptederror` | `中断错误` |
| `ioerror` | `IO错误` |
| `isadirectoryerror` | `是目录错误` |
| `keyboardinterrupt` | `键盘中断` |
| `keyerror` | `键错误` |
| `lookuperror` | `查找错误` |
| `memoryerror` | `内存错误` |
| `modulenotfounderror` | `模块未找到错误` |
| `nameerror` | `名称错误` |
| `notadirectoryerror` | `非目录错误` |
| `notimplementederror` | `未实现错误` |
| `oserror` | `操作系统错误` |
| `overflowerror` | `溢出错误` |
| `pendingdeprecationwarning` | `待删除警告` |
| `permissionerror` | `权限错误` |
| `processlookuperror` | `进程查找错误` |
| `recursionerror` | `递归错误` |
| `referenceerror` | `引用错误` |
| `resourcewarning` | `资源警告` |
| `runtimeerror` | `运行时错误` |
| `runtimewarning` | `运行时警告` |
| `stopasynciteration` | `停止异步迭代` |
| `stopiteration` | `停止迭代` |
| `syntaxerror` | `语法错误` |
| `syntaxwarning` | `语法警告` |
| `systemexit` | `系统退出` |
| `taberror` | `制表符错误` |
| `timeouterror` | `超时错误` |
| `typeerror` | `类型错误` |
| `unboundlocalerror` | `未绑定局部错误` |
| `unicodedecodeerror` | `统一码解码错误` |
| `unicodeencodeerror` | `统一码编码错误` |
| `unicodeerror` | `统一码错误` |
| `unicodetranslateerror` | `统一码转换错误` |
| `unicodewarning` | `统一码警告` |
| `userwarning` | `用户警告` |
| `valueerror` | `值错误` |
| `warning` | `警告` |
| `zerodivisionerror` | `零除数错误` |
## Example Code
Here's an example showing Chinese Python code with Legesher:
```python
# 示例:带错误处理的阶乘函数
从 typing 导入 Optional
定义 阶乘(n):
"""计算n的阶乘。"""
如果 n < 0:
提出 值错误("不允许负数")
否则如果 n == 0 或 n == 1:
返回 1
否则:
返回 n * 阶乘(n - 1)
定义 主函数():
数字列表 = [整数(x) 对于 x 在 范围(6)]
对于 数字 在 数字列表:
结果 = 阶乘(数字)
打印(f"{数字}! = {结果}")
# 演示while循环
计数 = 0
当 计数 < 3:
打印(f"计数: {计数}")
计数 += 1
# 演示try/except
尝试:
阶乘(-1)
除外 值错误 作为 错误:
打印(f"错误: {错误}")
最后:
打印("完成!")
如果 __name__ == "__main__":
主函数()
```
## Usage
```python
from legesher_i18n import LanguagePackLoader
# Load Chinese pack for Python 3.12
loader = LanguagePackLoader()
pack = loader.load("zh", "python", "3.12")
# Translate code
from legesher import translate
english_code = translate(your_zh_code, from_lang="zh", to_lang="en")
```
## Contributing
Found a better translation? We welcome contributions from native speakers!
1. Edit `legesher_i18n_python_zh/packs/<version>.yml` for the Python version where the term was introduced:
- `3.10.yml` - Base translations (most terms)
- `3.11.yml` - Terms added in Python 3.11 (e.g., `except*`)
- `3.12.yml` - Terms added in Python 3.12 (e.g., `type`)
- `3.13.yml` / `3.14.yml` - Future additions
2. Submit a pull request with your reasoning
3. Translations should be natural, commonly used in CS education, and easy to type