Where do I put common code for if and elif?
        Posted  
        
            by Vishal
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Vishal
        
        
        
        Published on 2010-04-09T06:16:38Z
        Indexed on 
            2010/04/09
            6:23 UTC
        
        
        Read the original article
        Hit count: 288
        
python
|conditional
For the example below:
 if a == 100:
     # Five lines of code
 elif a == 200:
     # Five lines of code
Five lines of code is common and repeating how can I avoid it? I know about putting it a function
or
if a == 100 or a == 200:
    # Five lines of code
    if a == 100:
        # Do something
    elif a == 200:
        # Do something
Any other cleaner solution?
© Stack Overflow or respective owner