DEV Community

Cover image for 40. Learning If Else in Python (Day 38)
Manoj Kumar
Manoj Kumar

Posted on • Originally published at emanoj.hashnode.dev

40. Learning If Else in Python (Day 38)

Today's lecture was a full immersion in Python Conditions and If statements. Reminded me of maths in school! In case you forgot, it's these:

= (equal to), > (greater than), < (less than)
a= b
b< c
c > d

How the if works in Python is:

a = 500 
b = 200 
if a > b: 
   print("a is greater")
Enter fullscreen mode Exit fullscreen mode

Print is used for giving an output. So, if we run those commands, you will get a result, in this case, "a is greater".

The elif

This word is a short form for "else if", which basically means - if a previous condition was false, then try another condition.

a = 500 
b = 200 
if a > b: 
   print("a is greater")
elif a = b:
   print("They are equals!")
Enter fullscreen mode Exit fullscreen mode

The else

This one is used if anything is outside of the previous conditions, or if it didn't meet any of the previous conditions.

a = 500 
b = 200 
if a > b: 
   print("a is greater")
elif a = b:
   print("They are equals!")
else:
   print("b is greater")
Enter fullscreen mode Exit fullscreen mode

Conclusion
So far so good. I understand the theory of the above, but I need a lot of practice! I asked the tutor if there were any websites that offer practice challenges and he referred me to the below two:

Leetcode

Codewars

They look great! This is exactly what I need to sharpen my coding skills and be more confident! I just need to find the time to do them though :( Perhaps, during my Christmas-New Year break coming up!

Time now - 10:25 and good night. It's drizzling out there.

Top comments (0)