Computer Science, asked by ghaffar0671329, 8 months ago

Give an example of for loop in python.​

Answers

Answered by Aryansingh001
1

Python For Loops

Python For LoopsA for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).

Python For LoopsA for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages.

Python For LoopsA for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages.With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.

Python For LoopsA for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages.With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.Example

Print each fruit in a fruit list:

fruits = ["apple", "banana", "cherry"]

for x in fruits:

  print(x)

The for loop does not require an indexing variable to set beforehand.

The for loop does not require an indexing variable to set beforehand.Looping Through a String

The for loop does not require an indexing variable to set beforehand.Looping Through a StringEven strings are iterable objects, they contain a sequence of characters:

The for loop does not require an indexing variable to set beforehand.Looping Through a StringEven strings are iterable objects, they contain a sequence of characters:Example

The for loop does not require an indexing variable to set beforehand.Looping Through a StringEven strings are iterable objects, they contain a sequence of characters:ExampleLoop through the letters in the word "banana":

for x in "banana":

  print(x)

The break Statement

The break StatementWith the break statement we can stop the loop before it has looped through all the items:

The break StatementWith the break statement we can stop the loop before it has looped through all the items:Example

Exit the loop when x is "banana":

fruits = ["apple", "banana", "cherry"]

for x in fruits:

  print(x)

  if x == "banana":

    break

Example

ExampleExit the loop when x is "banana", but this time the break comes before the print:

fruits = ["apple", "banana", "cherry"]

for x in fruits:

  if x == "banana":

    break

  print(x)

hope it help u plz follow me and mark me as a brainiliest

Answered by Anonymous
0

Answer:

A = [1,2,3,4,5]

for i in A:

print(i)

1

2

3

4

5

Explanation:

A for loop executes the code repeatedly.

the repetition of code completely dependents on the conditions.

Similar questions