The for loop is used to iterate over a sequence such as a list, string, tuple, or other iterable objects such as range. Using a for loop inside a for a loop is called a Python nested for.
for x in sequence: for y in sequence:
The outer loop can contain more than one inner loop without limitation on the chaining of loops.
Python nested for example
Simple example code for Nested loop to print multiplication table in Python
for i in range(0, 5): for j in range(0, 5): print(i * j, end=' ') print()
Nested for Loop to Print Pattern.
rows = 5 # outer loop for i in range(1, rows + 1): # inner loop for j in range(1, i + 1): print("*", end=" ") print('')
* * * * * * * * * * * * * * *
Do comment if you have any doubts or suggestions on this Python nested topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.