Skip to content

foreignthon-zh

Chinese language pack for ForeignThon — write Python in 中文.


Install

pip install foreignthon foreignthon-zh

Example

fizzbuzz.zh.py

定义 fizzbuzz(n):
    对于 i  范围(1, n + 1):
        如果 i % 15 == 0:
            打印("FizzBuzz")
        不然 i % 3 == 0:
            打印("Fizz")
        不然 i % 5 == 0:
            打印("Buzz")
        否则:
            打印(i)

fizzbuzz(20)

Compiles to standard Python:

def fizzbuzz(n):
    for i in range(1, n + 1):
        if i % 15 == 0:
            print("FizzBuzz")
        elif i % 3 == 0:
            print("Fizz")
        elif i % 5 == 0:
            print("Buzz")
        else:
            print(i)

fizzbuzz(20)

Run it directly:

fpy run fizzbuzz.zh.py

Keyword reference

Python 中文
if 如果
else 否则
elif 不然
for 对于
while 只要
def 函数 / 定义
class / 类别
return 返回
import 导入
from
as
in
and
or
not
True
False
None
print 打印 /
input 扫描
len 长度
range 范围
lambda 匿名 / λ
yield 产生
async 非同步
await

Full mapping: zh.json


Start a project

fpy new myproject --lang zh
cd myproject
fpy run src/main.zh.py

Documentation

foreignthon.keshavanand.net


Contributing

Found a missing translation or a better keyword choice? Open an issue or PR — no access to the core repo needed.


License

GPL v3