Python For Loops - Python Tutorial for Absolute Beginners

未能成功加载,请稍后再试
0/0

There are times that we may want to repeat a task a number of times.

For example, let's say we send a message to a user.

If that message cannot be delivered, perhaps we want to retry three times.

Now for simplicity, let's imagine this print statement is equivalent to sending a message.

In a real-world program, to send a message to a user, we have to write five to ten lines of code.

Now if you want to retry three times, we don't want to repeat all that code.

That is ugly.

That's when we use a loop.

We use loops to create repetition.

So here is how it works.

下载全新《每日英语听力》客户端,查看完整内容