Python for loop syntax

Created at 16-Mar-2021 , By samar

Python for loop syntax

Hello everyone, in this post we will examine how to solve the "Python for loop syntax" programming puzzle.

  • numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    for x in numbers:
    For loop syntax in python, for loop is used for iterating over a sequence that can be either a list, a tuple, a dictionary, a set, or a string. You have to just pass the comma separated value as a list and you can also pass string value. With the for loop we can execute a set of statements, once for each item in a list.
  • for letter in 'Python language':     
       print 'Current Letter :', letter
    Python for loop on string, you can use for loop on string. In python strings are iterable objects, they contain a sequence of characters. You can print each character of a string one by one and whitespace is also treated as a character in for loop.
  • list_of_lists = [ [1, 2, 3], [4, 5, 6], [7, 8, 9]]
    for list in list_of_lists:
        for x in list:
    Python for loop over Lists of lists, you can use for loop on lists of lists.

Back to code snippet queries related python

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.