Showing posts with label if elif else Statements. Show all posts
Showing posts with label if elif else Statements. Show all posts

August 7, 2019

if else elif statements in Python

Conditional Statements in Python

if syntax in Python:
if <condition>:
    do something

if-else syntax in Python:
if <condition>:
    do something
else:
    do something else

if-elif-else syntax in Python:
"if" expression ":" suite
  ( "elif" expression ":" suite )*
  ["else" ":" suite]

IF condition:

    stmt;

    stmt;

  ...
ELIF condition:

    stmt;
  ...
ELSE:

  stmt;

  ...

if "Br" in "Brother":
if "@" not in email_address:
if (3 <= Time <= 5):
  print "Office Hour"

if n % 2 == 0 :
  if n >=2 and n <=5 :
      print "Not Weird"
elif n >=6 and n <=20 :
    print "Weird"
  elif n >20 :
    print "Not Weird"         
else:
  print "Weird"


assert statement in Python:
assert 'category' not in d.keys()
assert T.number_of_selfloops() == len(find_selfloop_nodes(T))
assert len(sys.argv) == 2, "need start year as the one and only parameter"



Related Python Articles: Loops in Python   Tuples in Python