括号

Tip

宁缺毋滥的使用括号

除非是用于实现行连接, 否则不要在返回语句或条件语句中使用括号. 不过在元组两边使用括号是可以的.

  1. Yes: if foo:
  2. bar()
  3. while x:
  4. x = bar()
  5. if x and y:
  6. bar()
  7. if not x:
  8. bar()
  9. return foo
  10. for (x, y) in dict.items(): ...
  1. No: if (x):
  2. bar()
  3. if not(x):
  4. bar()
  5. return (foo)