Working on conditional flow :

imaginor-labs 15 June 19
Technology Comments

This is the continuation of series of blog post on getting started to data science using python . So today will explore the building blocks of python with special emphasis on conditional flow :

imag1

Python supports the usual logical conditions from mathematics:

  • Equals: a == b
  • Not equals: a != b
  • Less than: a < b
  • Less than or equal to: a <= b
  • Greater than: a > b
  • Greater than or equal to: a >= b

If-statement

imag2

Elif-statement

imag3

Else Statement:

imag4

And operator and Or operator
AND : The and keyword is a logical operator, and is used to combine conditional statements:

imag5

OR : logical operator if any one of the condition is true

imag6

Loops in python:

There are two loops in python :

  • While
  • For

While loop is the entry control loop i.e it will keep on iterate until the condition is false :

imag7

For Loops :

A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).

imag8
imag9
imag10
imag11
imag12

** Important note :
The most important thing to remember while using for loop is to correctly go through the indentation , a wrong indentation will make the whole process faulty .

These were some of the simple example working if conditional statement and working with Loops in python .
Happy learning and sharing !!

Comments:

Add a Comment:



Recent Posts: