我想缩短我的if, elif, else语句,如下所示:
transparency == False
if transparency == 'true':
transparency = True
elif transparency == 'false':
transparency = False
else:
transparency = True我试过的是:
transparency == False
transparency == 'true' ? True: False #boolean type我以为它会像javascript速记那样工作,我错了吗?
发布于 2017-08-03 07:31:24
你让事情变得太复杂了。只有在最初等于False的情况下,这个值才是'false',对于其他任何东西都是True。
transparency = transparency != 'false'否则,您的Javascript语法与Python混淆;Python条件表达式语法是拼写的。
<true_expr> if <test> else <false_expr>发布于 2017-08-03 07:31:11
基本上,如果transparency不是'false',那么它将是True。所以…
transparency = transparency != 'false'https://stackoverflow.com/questions/45477577
复制相似问题