Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

condition in python

# How conditions work
if condition:
	# if condition met
	# code here
elif condition2: # (else if) checked if the first condition is false
  	# if condition2 met
    # code here
elif condition3: # elif can be chained
    # if condition3 met
	# code here
else:
  	# if none of the conditions are met
    # code here

    
# example

if name == "bob": # ex. a == b (is a equal to b)
    print("the wifi password is 1234")
    
elif name == "jake": # if the first condition is not met python checks this one
    print("the secret formula is under the bed")

else: # if none of the conditions are met
    print("sorry i don't know who you are")

    
# Other Example
if age >= 18:
    print('You can go in')
else:
    print('you cannot pass, you are underage')
Comment

condition python

ensoleille = False
neige = True

if ensoleille:
   print("on va à la plage !")
elif neige:
   print("on fait un bonhomme de neige")
else:
   print("on reste à la maison !")
Comment

condition python

with_sun = True
in_week = False

if with_sun and not in_week:
   print("we go to the beach !")
elif with_sun and in_week:
   print("we go to work !")
else:
   print("we stay at home !")
Comment

condition python

avec_soleil = True
en_semaine = False

if avec_soleil and not en_semaine:
   print("on va à la plage !")
elif avec_soleil and en_semaine:
   print("on va au travail !")
else:
   print("on reste à la maison !")
Comment

PREVIOUS NEXT
Code Example
Python :: raw string python 
Python :: import matplotlib pyplot as plt 
Python :: add elements to list python 
Python :: python s3 
Python :: How to Send WhatsApp API using python 
Python :: fillna spark dataframe 
Python :: python set 
Python :: SUMOFPROD1 
Python :: sns.heatmap 
Python :: python array find lambda 
Python :: find string in list and return index python 
Python :: updateview 
Python :: run python version from terminal 
Python :: %s in python 
Python :: How do I plot a csv file in Jupyter notebook? 
Python :: check if key exists in sesison python 
Python :: how to run a command in command prompt using python 
Python :: string concatenation in python 
Python :: python integer to string format 
Python :: ngnix config 
Python :: django jsonresponse 
Python :: python catch any exception 
Python :: change python from 3.8 to 3.7 
Python :: how many numbers greater than 100 using pytho 
Python :: insert row in dataframe pandas 
Python :: lose your django secret key 
Python :: python data type conversion 
Python :: views django 
Python :: ttktheme example 
Python :: tkinter how to update optionmenu contents 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =