How to make if-elif-else statement in python more space-saving?
Posted
by Neverland
on Stack Overflow
See other posts from Stack Overflow
or by Neverland
Published on 2010-05-10T13:57:53Z
Indexed on
2010/05/10
14:04 UTC
Read the original article
Hit count: 196
I have a lot of if-elif-else statements in my code
if message == '0' or message == '3' or message == '5' or message == '7':
...
elif message == '1' or message == '2' or message == '4' or message == '6' or message == '8':
...
else:
...
Is it possible to format this in a more space-saving way?
I tried it this way:
if message == '0' or '3' or '5' or '7':
...
elif message == '1' or '2' or '4' or '6' or '8':
...
else:
...
But without success.
© Stack Overflow or respective owner