+ 1

What are 'if' statements?

18th Aug 2018, 11:48 AM
Praveen
4 Antworten
+ 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