+ 1
What are 'if' statements?
4 Answers
+ 4
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
+ 1
thanks bro great explaintionš
0
thanx