for loop with range()

本文介绍了Python中for循环结合range()函数的使用。range()函数生成一个指定范围内的数字序列,常用于控制循环次数。举例说明了如何利用for循环计算10到20之间的所有偶数之和以及如何计算列表中每个数的平方。for循环简化了重复任务的代码,提高了代码的可读性和效率,适用于已知迭代次数的情况或遍历序列进行操作。
摘要由CSDN通过智能技术生成

The range() function returns a sequence of numbers starting from 0 (by default) if the initial limit is not specified and it increments by 1 (by default) until a final limit is reached.

The range() function is used with a loop to specify the range (how many times) the code block will be executed. Let us see with an example.

For i in range(5) >>>----That means---->>> range(5) = Start=0, Stop=5, Step=1

Get started:

1st iteration - when i = 0 to execute code block

2nd iteration - when i = 1 to execute code block

3rd iteration - when i = 2 to execute code block

4th iteration - when i = 3 to execute code block

5th iteration - when i = 4 to execute code block

End 

Print su

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值