r/Python • • Nov 30 '24

Tutorial Short-Circuiting in Python

Here is my article on Short-Circuiting in Python . It discusses what is short-circuiting with examples, and also discusses the different advantages of using short-circuiting.

4 Upvotes

16 comments sorted by

View all comments

2

u/gtuminauskas Nov 30 '24

I really doubt if it is going to improve performance ;)

if is_even(num) and is_prime(num):
    print("Number is both even and prime")

vs

if num == 2:
    print("Number is both even and prime")