本文介绍了Python如果那么链等价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在翻译一个用Python编写的程序然后链接 IF x1<限制:---做一个--- IF x2<限制:---做b --- IF x3<限制:---做c --- .----- ------ IF x10< limt:---做j --- 那么 那么 ----- 那么 那么 那么 换句话说,只要''xi''小于''limit''继续下去 下行链路,当''xi''不小于''限制''跳转到结束时 链继续。 这是Python中的等价吗? IF x1<限制: ---做一个--- elif x2<限制: ---做b --- ---- ---- elif x10<限制: ---做j ---I''m translating a program in Python that has this IF Then chainIF x1 < limit: --- do a ---IF x2 < limit: --- do b ---IF x3 < limit: --- do c ---.-----------IF x10 < limt: --- do j ---THENTHEN-----THENTHENTHENIn other words, as long as ''xi'' is less than ''limit'' keep goingdown the chain, and when ''xi'' isn''t less than ''limit'' jump to end ofchain a continue.Is this the equivalence in Python?IF x1 < limit:--- do a ---elif x2 < limit:--- do b -----------elif x10 < limit:--- do j ---推荐答案 当然不是。在做一个之后,它会停止。 你需要使用 如果x1<限制: 做一个 如果x2<限制: 做b ... 或者,根据做X的性质,你可以做到/> 代表x,todo in((x1,do_a),(x2,do_b),...): 如果x<限制: 待办事项() 否则: 休息 这意味着尽管如此; DOS"纯函数没有(可变) 参数。 DiezOf course not. After "do a", it would stop.You need to useif x1 < limit:do aif x2 < limit:do b...Alternatively, and depending on the nature of "do X", you can dofor x, todo in ((x1, do_a), (x2, do_b), ...):if x < limit:todo()else:breakThis implies though that the "dos" are pure functions without (variable)arguments.Diez 在代码中''xi'和''限制''是变量和---做字母 --- 短语只是写入任何数组:an_array [xi] = 0 实际上,代码非常有意义,并且是我正在实现的算法的必要性,并且在Forth中工作得非常好,并且 可以在正常的页面宽度内写得非常好。 我只是希望能在Python中执行等效的链接 没有 必须严格缩进源代码超过 打印页面的正常宽度。 但是如果那个''是用Python做的唯一方法,那就这样吧。In the code the ''xi''s and ''limit'' are variables and the --- do letters---phrases are simply writes to any array: an_array[xi]=0Actually, the code makes perfectly good sense, and is a necessity ofthe algorithm I''m implementing, and works perfectly good in Forth, andcan bewritten quite nicely within a normal page width.I was just hoping I could perform the equivalent chain in Pythonwithouthaving to grossly indent the source code past the normal width of aprinted page.But if that''s the only way to do it in Python, then so be it. 这篇关于Python如果那么链等价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-22 16:39
查看更多