Learn Python Training from the Best Tutors
Search in
Asked by Kirti Last Modified
In Python, an iterative statement (also known as a loop) is a control flow statement that allows the programmer to execute a block of code repeatedly until a certain condition is met. There are two types of iterative statements in Python:
1. `for` loop: This loop is used for iterating over a sequence (such as a list, tuple, string, or range), or any other iterable object. The general syntax of a `for` loop is:
```
for variable in sequence:
# code to be executed
```
In this syntax, the `variable` takes the value of each item in the `sequence` one by one, and the code inside the loop is executed for each value of `variable`.
2. `while` loop: This loop is used for executing a block of code repeatedly as long as a certain condition is true. The general syntax of a `while` loop is:
```
while condition:
# code to be executed
```
In this syntax, the `condition` is checked at the beginning of each iteration of the loop, and if it is true, the code inside the loop is executed. The loop continues until the `condition` becomes false.
Here is an example of a `for` loop that iterates over a list of numbers and prints each number:
```python
numbers = [1, 2, 3, 4, 5]
for num in numbers:
print(num)
```
And here is an example of a `while` loop that counts from 1 to 5 and prints each number:
count = 1
while count <= 5:
print(count)
count += 1
View 1 more Answers
Related Questions
Main problem statement : import a .xlsx file in python with a dataset value then after import we need to ensure that every time I enter a value in a row ; row must be added by 1 and automatically value changes to a row using python script without manually intervention .
Hi i am vishnu. I did my Post Diploma in Tool design after DME and am now working in an MNC as contract base which will be completed on April 2020. Now i am in search of a job and i want to know any other courses like PYTHON or SAP which is best as i am not having any job opportunities in my domain. Please suggest a course and tell me whether I can do it or not as I only hold a Diploma degree
Thankyou
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Top 5 reasons why you should learn Python
Python is one of the most popular programming languages in the world. It is general-purpose, object oriented, high-level programming language used in a number of programming fields. Python is a great programming language to learn as it will introduce you to the world of programming. If you are from the technical background...
Read full article >
Learn Hadoop and Big Data
Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...
Read full article >
Learn Microsoft Excel
Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...
Read full article >
What is Applications Engineering all about?
Applications engineering is a hot trend in the current IT market. An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company’s manufacturing, marketing, sales, and customer...
Read full article >
Looking for Python Training classes?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for Python Training Classes are on UrbanPro
The best Tutors for Python Training Classes are on UrbanPro