+ 1

What are 'if' statements?

18th Aug 2018, 11:48 AM
Praveen
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
18th Aug 2018, 12:03 PM
Maninder $ingh
Maninder $ingh - avatar
+ 1
thanks bro great explaintionšŸ˜„
18th Aug 2018, 1:42 PM
Praveen
0
thanx
18th Aug 2018, 1:46 PM
Praveen