dimanche 7 janvier 2018

Do Nested If Statements Evaluate Differently to If... And Statements?

I have recently been ripping my hair out trying to track down a bug, and I've come to realize that my understanding of how Python evaluates statements is lacking in some respects.

Does Python make any relevant differences in how it handles nested if statements vs. if... and blocks?

For example:

if profile_username == input_username and profile_password == input_password:
    log_in(loaded_profile)

How does this differ from

if profile_username == input_username:
    if profile_password == input_password:
        log_in(loaded_profile)

They both evaluate lazily, and they both require both conditions to be met, but otherwise, I don't know if they're identical.

Will one version create some behavior (BUGS???) that the other won't? In a situation like this, is it simply programmer preference which one to use?

Aucun commentaire:

Enregistrer un commentaire