Master The Art Of The, If And Else: Statements In Python!!

Table of contents

No heading

No headings in the article.

Hello there!! I'm Gold and I am going to help you understand what the conditionals, if and else statements in python are all about!!
Exciting right?? Well, let's get to it!!

Okay, I am going to get straight to what conditionals are all about ... I am not going to be showing or explaining it the traditional way. I need you to understand it in the simplest way possible!

Conditionals in python are used to give conditions to a variable that has been defined. What do I mean?? Let's use a very simple, yet practical example!

Do You remember when you were a kid and you needed to ask your parents for permission on something and they would be like, " If you want this candy, then, you are going to have to clean the house? Else, shut up and sleep!"

lol, it might not have happened in that exact sequence but this is a very practical way to explain conditionals. Now the parent gave the condition that simply meant, if you were interested in eating the candy all you had to do was clean but if you were going to be stubborn and not agree you should sleep.

It's like saying, 'if you don't do this then, do that!'

That's basically how the if and else statement works.

Now... wait! that's not all... When dealing with these two conditionals or any conditional, indentation plays a really big role... Indentation is basically like creating a hierarchy of execution. Like telling the editor which code is the sub of the other, using spaces.

Another simple yet very important thing to note is the use of a colon(:) the colon must be written immediately after every condition is given else, the code would not run.

The last thing to consider is the operator '=='. It compares two values. And you'll understand better with an example.

Here's an example using the same scenario of the candy.

I hope you now understand and have mastered the concepts of the if and else statements in python!!

Please follow me on my Twitter account... lol I recently just opened it!
https://twitter.com/Golden_builds