+ 1
Not understanding if statement
help please
2 Answers
+ 2
We use if statements in our everyday life all the time â even if our everyday life is not written in Python. If the light is green then Iâll cross the road; otherwise Iâll wait. If the sun is up then Iâll get out of bed; otherwise Iâll go back to sleep. Okay, maybe itâs not this direct, but when we take actions based on conditions, our brain does what a computer would do: evaluate the conditions and act upon the results. Well, a computer script doesnât have a subconscious mind, so for practice for computer programming we have to understand how an if statement works and how we can apply it in Python!
Letâs say we have two values: a = 10 and b = 20. We compare these two values: a == b. This comparison has either a True or a False output.
We can go even further and set a condition: if a == b is True then we print 'yes'. If itâs False then we print 'no'. And thatâs it, this is the logic of the Python if statements.