DAY-7 || Control Statements -2 ||

Python

DAY-7 || Control Statements -2 ||

Hello World!!! It’s JITHU….. Welcome back to the day-7 of your programming life. As you know that programming is the key skill nowadays, But why only python as it simple and good for the beginners, That’s it??? Not really Because it consists of a lot of rich libraries that make our work a lot simpler.OK let me stop this and dive into our DAY-7 Tutorial.

Welcome Back Wizards!!!! Let’s continue the Session-2 of the Control statements…..

3] Iterative Control Statements:  

What is Loop?

Loop is a continuous process that occurs in a repetitive manner until the condition is satisfied. Here the statements are executed in a sequential manner until the condition is proved.

Different Types of loops in python:

1] For loop.

2]while loop.

3]Break and Continue.

There are only for loops let me wrap it know in this… Firstly.

1)For Loop:

Python is normal English based language, so it is used most popularly. when we will use FOR ok I will tell you FOR, example Yeap you got it now we used it in the same manner if  I want to extract each character in my spelling here I am using For loop.

Here I used “x” as a variable that stores my every character of my name. “For” as an Iterator, “in”           as an operator that is used to check present in the given string, and finally “Jithu stark” is an             Iterable.

The complete statement (for x in “Jithu stark”)  is an iteration.

Syntax: for var_name in sequence:

action_1

 

Range Functions:

It generates lists containing arithmetic progression and returns the list of integers. There are 3 types of Ranges:

1] range(stop)

2] range(start,stop)

3] range(start,stop,step)

Let me complete this with one example each,

1] range(a):

Here it generates a sequence of numbers from 0 to a, excluding a, and incrementing by 1.

Syntax: for <variable> in range(<number>):

Here range(5) excluding the value 5, in “Python            the indexing starts from 0”

 

 

 

 

 

2]  range(a,b):

Here it generates a sequence of numbers from a to b, excluding b, and incrementing by 1.

Syntax: for <variable> in range(<start_number>,<end_number>):

3] range(a,b,c):

Here it generates a sequence of numbers from a to b, excluding b, and incrementing by c.

Syntax: for <variable> in range(<start_number>,<end_number>,<step>):

Break:

Actually it breaks the program at a specific condition.

 

 

 

Here when num == 4, then the process has been broken so, only the 1st three numbers have been printed.

 

 

Continue:

Here the condition is Broken at a specific region then, later it continues at the next level.

While Loop:

It is used to execute no.of statements until the end of the condition is true, if the condition is false the control will be out of the loop.

Syntax: while(expression):

statement

EXTRA SALT and PEPPER:

What is the difference between COMMENTS and PASS?

Comments are the non-executable Statements, While the Pass is an executable statement But NO OPERATION(NOP).

 

One thought on “DAY-7 || Control Statements -2 ||

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.