Re: [闲聊] 做程式的请进

楼主: Apache (阿帕契)   2024-02-05 20:53:44
※ 引述《Wardyal (我独自升级 超级好看!)》之铭言:
: 我今天在用写一个测试的软件 到时候会包成exe
: 写法就
: global_var1
: global_vaw2...
: def test_fun1():
: ...
: def test_fun2():
: ...
: if __name__ == "__main__":
: ret = []
: test_funs = [test_fun1, test_fun2...]
: for i in range(CASE_AMOUNT):
: ret.append(test_funs[i](...))
: ...
: # 印出结果
: 写是差不多写完了 但是总感觉哪里怪怪的 好像没有到很美观
: 其他像是一些要判断很多的 写到后面变成
: if ...:
: if ...:
: if ...:
: return 1
: else:
: return -3
: else:
: return -2
: else:
: return -1
: 这种感觉
: 这个的话有啥比较好的写法吗
你可以
match conditions:
case (False, _, _):
...
case (_, False, _):
...
case _:
...
https://peps.python.org/pep-0636/
不过我记错了 这是3.10就有的
太苦了
作者: wu10200512 (廷廷)   2024-02-05 20:57:00
C++有类似这个的东西吗
作者: Wardyal (Wardyal)   2024-02-05 20:57:00
没用过 我看一下
作者: ILoveErr (英梨梨我老婆)   2024-02-05 21:00:00
懂了 用rust
楼主: Apache (阿帕契)   2024-02-05 21:00:00
Rust有 C++到23好像都还没有

Links booklink

Contact Us: admin [ a t ] ucptt.com