gpt4 book ai didi

Python #define 等效项

转载 作者:太空狗 更新时间:2023-10-29 22:30:10 25 4
gpt4 key购买 nike

我正在为我还不会说英语的 child 开发一个希伯来语 python 库。到目前为止,我已经设法让它工作了(函数名和变量工作正常)。问题在于“if”、“while”、“for”等语句。例如,如果这是 C++,我会使用

#define if אם

Python 中的#define 是否有任何替代方案?

*****编辑*****现在,一个快速而肮脏的解决方案对我有用;我没有运行程序,而是运行这段代码:

def RunReady(Path):
source = open(Path, 'rb')
program = source.read().decode()
output = open('curr.py', 'wb')

program = program.replace('כל_עוד', 'while')
program = program.replace('עבור', 'for')
program = program.replace('אם', 'if')
program = program.replace(' ב ', ' in ')
program = program.replace('הגדר', 'def')
program = program.replace('אחרת', 'else')
program = program.replace('או', 'or')
program = program.replace('וגם', 'and')
output.write(program.encode('utf-8'))
output.close()
source.close()
import curr

current_file = 'Sapir_1.py'
RunReady(current_file)

最佳答案

Python 3 有 33 个关键字,其中只有少数是初学者使用的:

['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'case', 'class', 'continue', 'def', 'default', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'match', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

鉴于 Python 不支持重命名关键字,在教授编程的同时教授其中一些关键字可能更容易。

关于Python #define 等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28138596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com