Dávid Papp
Dávid Papp

Reputation: 97

How to avoid repeating suits in if statements?

I have a code that looks:

if condition1:
  do1
  if condition2:
    do2
  else:
    do3
else:
  do3

where do2 and do3 operate on the same variables. Is there a way to reduce this code somehow, to avoid having do3 twice?

Thanks!

Upvotes: 1

Views: 106

Answers (1)

Alvison Hunter
Alvison Hunter

Reputation: 673

I would think of something like this to avoid do3 twice

if condition1:
    do1
elif condition2:
    do2
else:
    do3

Upvotes: 1

Related Questions