美文网首页
无标题文章

无标题文章

作者: Edan栋 | 来源:发表于2017-02-01 00:12 被阅读10次

    每行一个声明

    复合语句(比如说列表推导)因其简洁和表达性受到推崇,但在同一行代码中写 两条独立的语句是糟糕的。

    糟糕

    print 'one'; print 'two'if x == 1: print 'one'if <复杂的比较> and <其他复杂的比较>:    # 做一些工作

    优雅

    print 'one'

    print 'two'

    if x == 1:  

    print 'one'

    cond1 = <复杂的比较>

    cond2 = <其他复杂的比较>

    if cond1 and cond2:    # 做一些工作

    相关文章

      网友评论

          本文标题:无标题文章

          本文链接:https://www.haomeiwen.com/subject/siqvjttx.html