-1

I have a question about a logical expression of the following sort:

for i in range (k): #k is large
    if (a==b and test(c)==b): #test() takes some time to calculate
         do something

Now I want to know, how the logical expression is processed. Are the two simple expressions calculated first and then combined via and? Or is a==b calculated, and in case it is False, test(c)==b neglected?

Thanks.

Y.J.
  • 1

1 Answers1

2

The a==b will be calculated first, and if it's true then the second expression will be evaluated. This is known as 'short-circuiting', see the docs.

Duncan WP
  • 830
  • 5
  • 19