Data Sci Lab 5
Data Sci Lab 5
Data Sci Lab 5
Lab No: 05
OBE MARKS
Introduction:
Python, known for its simplicity and versatility, offers a range of control structures to manage the flow of
a program. Among these, the "while" loop is a fundamental construct that allows you to execute a block
of code repeatedly as long as a certain condition remains true. In this article, we'll delve into the world of
“for" loops in Python, exploring their basics, working mechanism, advantages, common use cases, and
practical examples.
Using the Range() Function. The range() function is commonly used to create a sequence of
numbers. It's especially useful when you want to iterate a specific number of times or generate a
range of values. This code prints numbers from 1 to 10.
Nested 'for' loops are used to create more complex iterations. You can loop through multiple
sequences simultaneously, allowing for more intricate data processing:
Fig #5.5(Nested for loops)
Conclusion:
'For' loops are fundamental to Python programming, offering a straightforward way to automate tasks and
process data. Mastering 'for' loops will empower you to write more efficient and effective code, making
your programming endeavors easier and more productive.