range函数python_Python Range函数简介。

range函数python 范围: (Range:)The range type represents an immutable sequence of numbers and is commonly used for looping a specific number of times in for loops. 范围类型表示数字的不可变序列,并通常用于在for循环循环的特定次数。 range...
摘要由CSDN通过智能技术生成

range函数python

范围: (Range:)

The range type represents an immutable sequence of numbers and is commonly used for looping a specific number of times in for loops.

范围类型表示数字的不可变序列,并通常用于在for循环循环的特定次数。

range(stop)
range(start,stop,step)

startThe value of the start parameter (or 0 if the parameter was not supplied)

start start参数的值(如果未提供该参数,则为0 )

stopThe value of the stop parameter

stop stop参数的值

stepThe value of the step parameter (or 1 if the parameter was not supplied).If the step is 0, it will raise ValueError.

step step参数的值(如果未提供该参数,则为1 )。如果step为0,则将引发ValueError。

The arguments to the range function should be integers. (either built-in int or any object that implements the __index__ special method)

范围函数的参数应为整数。 (内置int或实现__index__特殊方法的任何对象)

Example 1:Only the stop parameter is given.

示例1:仅给出stop参数。

range(10)

range(10)

  • start by default will be 0 and step by default will be 1

    默认情况下, start0 ,默认情况下, step1

  • stop is given as 10.

    stop10

  • stop value is excluded. It generates value until 9 only.

    停止值被排除。 它直到9才产生值。
  • It will return a range object containing numbers starting from 0 to 9.

    它将返回一个范围从0到9的数字的范围对象。

  • We can convert the range object to list using list() constructor.

    我们可以使用list()构造函数将范围对象转换为列表。

  • We can also iterate using for loop

    我们还可以迭代使用for循环

r=range(10)
print (r)#Output:range(0, 10)print (type(r))#Output:<class 'range'>print (list(r))#Output:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Example 2:Only the start and stop parameter is given.

示例2:仅给出start和stop参数。

range(1,10)

range(1,10)

  • step by default will be 1

    默认情况下, step1

  • It will generate a sequence of numbers starting from 1 to 9.

    它将生成一个从1到9的数字序列。

r=range(1,10)
print (r)#Output:range(1, 10)
#Converting range object to list
print (list(r))#Output:[1, 2, 3, 4, 5, 6, 7, 8, 9]

Example 3:start, stop and step parameter is given

<
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值