Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways

Loop in Python

Loop and functions are two most important topics in the basics of Python. You need to have a really good hand on loop and functions.

Loop is basically used to iterate the same thing again and again. Python, like most of the programming language, have two types of loop:-
1. while
2. for

While loop
In a while loop, a condition is checked first and then the content or body of the loop is executed.
A simple while loop is executed below

There are two more keywords which are used inside the body of a loop:-
1. break
2. continue

Break command is used to stop a loop at a particular condition and it pulls the control out of the loop. See the example below

Break statement stops the loop at the given condition

Continue statement is used to bypass a particular instance

Use of continue statement

2. For loop

A for loop is used for iterating over a sequence which could be anything like a list, a tuple, a dictionary or a set.

Let’s understand each with the help of some examples:

a. Applying loop on a list

b. Applying loop on a list with break statement

c. Using range keyword. Range starts with 0 and ends at n-1 where n is the parameter in the range() function

d. Using range keyword with increment

e. Nested loop

f. Looping through all the key-value pair of a dictionary

g. Looping through all the values of a dictionary

h. Looping through all the keys of a dictionary

i. Print the following pattern
1
22
333
4444

j. Reverse a list using loop

h. Reverse a string using loop, example to do it without loop is given below:

If you want to learn more about some tricky Python Questions then do check out our book on Amazon

1. 100 Python Questions to crack Data Science/Analyst Interview
2. The Monk who knew Linear Regression (Python): Understand, Learn and Crack Data Science Interview

Keep practicing Machaa 🙂

XtraMous

The Data Monk services

We are well known for our interview books and have 70+ e-book across Amazon and The Data Monk e-shop page . Following are best-seller combo packs and services that we are providing as of now

  1. YouTube channel covering all the interview-related important topics in SQL, Python, MS Excel, Machine Learning Algorithm, Statistics, and Direct Interview Questions
    Link – The Data Monk Youtube Channel
  2. Website – ~2000 completed solved Interview questions in SQL, Python, ML, and Case Study
    Link – The Data Monk website
  3. E-book shop – We have 70+ e-books available on our website and 3 bundles covering 2000+ solved interview questions. Do check it out
    Link – The Data E-shop Page
  4. Instagram Page – It covers only Most asked Questions and concepts (100+ posts). We have 100+ most asked interview topics explained in simple terms
    Link – The Data Monk Instagram page
  5. Mock Interviews/Career Guidance/Mentorship/Resume Making
    Book a slot on Top Mate

The Data Monk e-books

We know that each domain requires a different type of preparation, so we have divided our books in the same way:

1. 2200 Interview Questions to become Full Stack Analytics Professional â€“ 2200 Most Asked Interview Questions
2.Data Scientist and Machine Learning Engineer -> 23 e-books covering all the ML Algorithms Interview Questions
3. 30 Days Analytics Course – Most Asked Interview Questions from 30 crucial topics

You can check out all the other e-books on our e-shop page â€“ Do not miss it


For any information related to courses or e-books, please send an email to [email protected]

About TheDataMonkGrand Master

I am the Co-Founder of The Data Monk. I have a total of 6+ years of analytics experience 3+ years at Mu Sigma 2 years at OYO 1 year and counting at The Data Monk I am an active trader and a logically sarcastic idiot :)

Follow Me