python for loop if else code example
Example 1: python for else
list = [99, 98, 97, 96, 95, 94]
for number in list:
if number == 2:
print("There is a 2 in the list")
break
else:
print("There are no 2's in the list")
Example 2: if statement in python
answer = input(":")
if answer == "lol":
print("haha")
else:
print("not haha")
exit()
please note that the exit() command is optional and is not necessary.
Example 3: if else python
if condition:
result
elif condition:
result
else:
result
Example 4: if loop in python syntax
if a>b :
print(a)