Skip to main content

Command Palette

Search for a command to run...

42. Learning If Else in Python (Day 38)

Published
2 min read
42. Learning If Else in Python (Day 38)
M

I've just started my journey in learning to code and using Hashnode to chronicle my learnings and experience. Besides this, I work full-time and dabble in vlogging, podcasting, drawing, startup ventures, and fitness training.

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")

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!")

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")

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:

https://leetcode.com/

https://www.codewars.com/

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.

Learning to Code

Part 30 of 50

In this series, I will share lessons learned from my intense 10-month coding bootcamp, starting Tuesday, 17 October 2023. The course aims to develop me into a full-stack web developer.

Up next

41. Embracing Institutional Learning (Day 37)

Nurturing Humility and Structure in Coding Education"

More from this blog

Manoj's coding diary

71 posts

I am Manoj Kumar, from Sydney, Australia. I am focusing on sharing my study of coding as a complete beginner here. My other activities: full-time work, blogging, vlogging, drawing & podcasting.