[Python] When is a Python operator a line continuation?

Discussão em 'Python' iniciado por Stack, Maio 25, 2025.

  1. Stack

    Stack Membro Participativo

    The following is syntactically invalid:

    if extremely_long_condition_that_takes_up_a_whole_line and
    another_condition:
    # Do something


    The following is valid:

    if (extremely_long_condition and
    another_condition):
    # Do something


    Why are these different? More generally, why is #2 okay but #1 somehow dangerous/ambiguous? I can't see how the first statement is or generalizes to an ambiguous statement.

    Continue reading...

Compartilhe esta Página