再请教一个 Python if 语句的写法

2018-04-26 16:20:21 +08:00
 coolair
if A1:
    if A2 == X2:
        if B1:
            if B2 == Y2:
                do_something()
            else:
                print 'B2 must equal to Y2'
        else:
            do_something()
    else:
         print 'A2 must equal to X2'
elif B1:
    if B2 == Y2:
        do_something()
    else:
        print 'B2 must equal to Y2'
else:
    print 'Choose at least one between A1 and B1'
1167 次点击
所在节点    问与答
2 条回复
pktangyue
2018-04-26 16:36:22 +08:00
if not A1 and not B1:
print 'Choose at least one between A1 and B1'
return
if A1 and A2 != X2:
print 'A2 must equal to X2'
return
if B1 and B2 != Y2:
print 'B2 must equal to Y2'
return

do_something()
xmadi
2018-04-26 16:41:11 +08:00
。。。。 这个和语法没有关系了 纯粹是逻辑归纳能力不行

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/450117

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX