Conditional Branching in Python
if,pass,if-else and so on..
- Conditional Branching in Python
- Some Branching Statement in python
- If statement
- Pass statement
- If-else statement
- AND , OR operator
- If-elif-else statement
- in keyboard
- Check empty or not
Conditional Branching in Python
Conditions in Python are comparable to those in all C-like languages. The if keyword is used to create conditions, which are then followed by a logical statement and a colon (:). If the expression returns true, the next sentence will be carried out. If it is false, the program will move on to the next statement without skipping the previous one.
age=int(input("enter your age"))
if age>=14 :
print("you are greater than 14 years old")
Pass statement
Pass statements are typically used as placeholders.
Let's say we have a loop or function that isn't used right now but that we wish to in the future. They cannot have an empty body. An error would be displayed by the interpreter. Therefore, we create a body that accomplishes nothing using the pass statement.
x = 18
if x >18:
pass
age=int(input("enter your age"))
if age>=14 :
print("you are greater than 14 years old")
else:
print("you are smaller than 14")
name = 'anisha'
age = 20
if name == "anisha" and age == 20:
print ("She is good girl")
else:
print ("She is not like anisha")
name = 'abc'
age = 20
if name == "abc" and age == 20:
print ("She is good girl")
elif name == "abc" or age == 19:
print ("She is bad girl")
else:
print("I don't know about her")
name = "Anisha"
if 'A' in "Anisha":
print("true")
else:
print("False")
name = "anisha"
if name:
print("not empty")
else:
print("is empty")