Loops in Python
Python : Loops
Loops are used to execute a block of code repeatedly. There are two types of loops in Python:
for
loops andwhile
loops.
For Loops in Python
A for loop is used to iterate over a sequence (such as a list, tuple, or string) and execute a block of code for each item in the sequence.
The syntax for a for loop in Python is:
for item in sequence:
# code block to execute for each item
While Loops in Python
A while loop is used to execute a block of code repeatedly as long as a certain condition is true.
The syntax for a while loop in Python is:
while condition:
# code block to execute while condition is true
Previous Article
Next Article
Python Tutorials
- Hello World
- Variables and Types
- Lists
- Tuple
- Basic Operators
- Strings
- Conditions
- Loops
- Functions
- Classes and Objects
- Dictionaries
- Map
- Filter
- Reduce
- Sets
- Decorators
- Generators
- Modules and Packages
- Numpy Arrays
- Pandas Basics
- List Comprehensions
- Lambda functions
- Multiple Function Arguments
- Partial functions
- Regular Expressions
- Exception Handling
- Serialization
- Code Introspection