Posts

Showing posts from July 28, 2019

Python Programming Looping Techniques, For Loop in Python Programming and While Loop in Python Programming | Python Programming

Image
Python Programming Looping Techniques, For Loop in Python Programming and While Loop in Python Programming For loop in Python Programming What is for loop in Python Programming? The for loop in Python Programming is used to iterate over a sequence (list, tuple, string) or other iterable objects. Iterating over a sequence is called traversal. Syntax of for Loop for val in sequence:     Body of for Here, val is the variable that takes the value of the item inside the sequence on each iteration. Loop continues until we reach the last item in the sequence. The body of for loop is separated from the rest of the code using indentation. Flowchart of for Loop Example: Python for Loop # Program to find the sum of all numbers stored in a list # List of numbers numbers = [ 6 , 5 , 3 , 8 , 4 , 2 , 5 , 4 , 11 ] # variable to store the sum sum = 0 # iterate over the list for val in numbers:     sum = sum +val # Output: The sum is 48 print ( "The sum is" , sum ) when you run th