Search code examples
pythonif-statementorganization

Return conditional statements to new line when organizing code(Python)?


So I know when listing variables in object class, you can return every line to list the variables vertically for better organization:

class Thing(object):
  def __init__(x,
               y,
               z):

Is it possible to do the same thing with conditionals in an if statement, like so?

if condition1 and
   condition2 and
   condition3:

Obviously that's probably not the right syntax for it since it doesn't work, but it's a good example of what I'm trying to do in order to organize my code so I don't have scroll to right when something has long names for conditional satements.


Solution

  • Parentheses to the rescue!

    if (1 == 1 and
        2 == 2 and
        3 == 3):
       # ...