Ask Your Question
0

How can I program a Loop in Python?

asked 2023-04-05 16:14:25 +0000

woof gravatar image

updated 2023-04-06 11:40:41 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-04-05 16:16:09 +0000

qstack gravatar image

updated 2023-04-07 18:29:55 +0000

In Python, you can create a loop using a variety of statements, but the most common are the for and while loops.

A for loop is used to iterate over a sequence (such as a list, tuple, or string) and execute a block of code for each item in the sequence. Here is an example of a for loop that prints each item in a list:

my_list = [1, 2, 3, 4, 5]
for item in my_list:
    print(item)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

1 follower

Stats

Asked: 2023-04-05 16:14:25 +0000

Seen: 18 times

Last updated: Apr 07 '23