Blog Details

img
Data Science

What is the for loop in Python

Spoke Right / 16 Nov, 2023

Python For Loop is a loop statement which can be used in various forms to execute a block of code continuously as long as the condition of the loop is true, and stops only when the condition fails. These are:

For Loop :

For loop is used to execute a group of action only for a specified number of times.

Syntax:

for <variable> in <sequence>:

code to be executed till the condition is true

Nested For Loop :

Nested For loop is For loop inside a For loop and so on which is used to run multiple loop conditions.

Syntax:

for <variable> in <sequence>:

for <variable> in <sequence>:

code to be executed till the condition is true

Example:

//pythonexample.py

print "Letters in word ALPHANUMERIC are:"
for x in "ALPHANUMERIC":
   print x

0 comments

Warning: PHP Startup: Unable to load dynamic library 'imagick.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20210902/imagick.so (/usr/local/lib/php/extensions/no-debug-non-zts-20210902/imagick.so: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20210902/imagick.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20210902/imagick.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0