Python Fundamentals

Python If Elif Else

it’s all about making decisions, and Python If Elif Else is providing a way using conditions (comparison operators) in a flow-chart to make a decision

Python If Elif Else ( Comparison Operators )

those operators checks and compare between values saved in variables, let’s see

  • ==   : A == B   .. True/False .. Equal check
  • !=    : A != B    .. True/False .. Not Equal check
  • <>   : A <> B   .. True/False .. Not Equal check
  • >     : A > B     .. True/False .. Bigger check
  • <     : A < B     .. True/False .. Smaller check
  • >=   : A >= B   .. True/False .. Bigger or Equal check
  • <=   : A <= B   .. True/False .. Smaller or Equal check

Python If Elif Else ( If )

if (expression test):
    statement(s)

t’s the most-known flow control option in almost every language

simply, from the start point, there is one way, if true then execute statements

if not ignore the inside block of code

python if

cars = 5

if cars > 3:
     print('we still have cars')

Python If Elif Else ( If Else )

if (expression test):
    Statement(s)
else:
    Statement(s)

simply, from the start point, there are two ways

if true then execute statements, if not do else block of code

cars = 5

if cars > 3:
     print('we still have cars')
else:
     print('we should buy some')

Python If Elif Else

simply, from the start point, there are as many ways as we need

if true then execute statements, if not do else statements

elif true then execute it’s block of code

python if elif else

cars = 5

if cars > 3:
     print('we still have cars')
elif cars > 5:
     print('we still have cars')
     print('we have enough for this week')
else:
     print('we should buy some')

How To Think That Way

We got a new job which is product quality control specialist

so, i’ll setup my environment to control production process and check piece-by-piece quality

there are 3 process, producing – covering – checking

so we will go to first machine to tell here if material quality >= standards , then continue, anything else then throw it away

and for the second process, check if it completely done on the way we want then cover it, elif needs more time on the first machine then return it back, anything else then throw it

and for quality control process i’ll get my pen and paper to set the rules into variables and flow control for objects and so on..

liked it ! .. keep up with Python Monsters

python if elif else2

Write a Comment

Your email address will not be published. Required fields are marked *