My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Python: 100 days of code

Igben Christopher's photo
Igben Christopher
·May 30, 2022·

2 min read

I started my 100 days of code in python language and I am feeling really good about it. I already had basic understanding in programming as a result of some college courses I took on C++ and JAVA programming language. I was able to wrap my head around the data types, variables declaration, numbers and string faster given my previous knowledge. I quickly moved to flow control, where I learnt the use of IF, Elif and Else statement in python.

The IF statement in python language, allows user to control the flow of their program after setting various conditions to be met. The statement doesn't allow the program to run from top to bottom in sequence(line by line) unless certain conditions are met. After declaring the IF keyword, the comparison statement follows ending with a full colon (:) which signifies to python that is a block of code( speaking in JAVA) otherwise known as indentation in python.

The Elif known in some languages as Else If statement, works pretty much as the IF statement. The Elif allows the program to carry out more than one comparison as different scenario might be involved in the execution of a problem.

The Else statement, is more like a last resort stamement, that tells python, should any condition not be met, run this block of code.

In the use of comparison operators, python in a bid to make programming languages closer to human language allows the use of AND, OR and NOT logic operators to make comparison (for someone coming from another programming language as C++ or JAVA, you are accustomed to the use of &&, || and ! as logic operators for AND, OR and NOT respectively).

NOTE:

  1. No else statement can exist without an IF.
  2. An else statement on the same indentation as an if statement, goes hand in hand with the IF statement else you get a traceback
  3. Be careful with indentation in python.