期待一片阳光 发表于 2022-3-10 08:13:01

为什么range(1,10)函数没有返回list

在许多资料中说的range()函数返回的是list数据集,例如range(1,10)应该返回【1,2,3,4,5,6,7,8,9,10】
但我在测试:
>>>range(1,10)
range(1,10)
>>>
http://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAxIAAAC9CAIAAACoBNw6AAAeLUlEQVR4nO2d2+8sSV3A5/+ZRxJNJOoRQV3p4B7FBLwQJBxDtINudl0iFz3sBbbBxWVVBEEFsWFluaxcF7nsPOi6IWJ4OC+KxM0qss++4NvPh57prsu3vlVdXT2/nu7PJ5OT85vprqquqq7+zLdqundXAAAAAJDA7tsAAAAAkMDuur0NAAAA4DJAmwAAAACSQJsAAAAAkkCbAAAAAJJAmwAAAACSQJsAAAAAkkCbAAAAAJJAmwAAAACS2N35znO8ePHixYsXL16X9bpx48b1aNP5cwUAAADI5vbt29epTdfujLx48eLFixcvXokvtIkXL168ePHixSvptQhtuj0P71R5IMaDKg/FeFjlXTHerfKIShPjPSrvjfFHKo/GeJ/KH8d4TOX9Ko/H+BOVP43xZyofiPHnKh9U+VCMv1D5cIyPqPxljL9S+esYH1X5mMrfxPi4yt/GaFU+EeOTKk+o/F2MT6k8GePTKp+J8VmVz8V4SuXvVT4f4wsqX4zxJZUvx/iKytMqX43xDypfi/F1lW/E+KbKMyqHxYM2oU1oE9qENqFNaBPahDYlsURt2r31XxJfaBPahDahTWgT2oQ2rUybRpnEWH25ceNGXi5oE9qENqFNaBPahDahTUvUprFrjEZtn5fLcrXp1q1bL0vg1q1bG9emrt6uXZu6YqBNaBPahDahTWjT9WrTLsz6teklH3pJ90rRJv8IR2lTv2NZbTKLpGiT30Ip2mQ6k7mvo03dm4o29Tv62tS9nxJt8s0JbUKb0Ca0CW1Cmy5Fm8xt/HcuQ5t8br729Xe/vn7V635bjDb1iTipibbUbWNGm4prk2lLIXMytcn8T1SbfGcy/9NrU9/8erQppE0ivUs54SXHnNAmtAltQpvQJrTp/NokbpYSbTI9ybG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AgAAAEgiw5bQJgAAANgiRJsAAAAAksiwJbQJAAAAtgjRJgAAAIAkMmxpmdqk3FUp7yMAAAAAizVFm5RbEuV9BAAAADCQYUuL1aadegPsvI8AAAAAjqwp2tSBOQEAAMAsZNjSwrVphzkBAADAHKwv2tShPBk37yMAAADYOhm2dBHaxE/rAAAAoDBEmxI/AgAAgK2TYUvL1ybWNgEAAEB51hdt4u5NAAAAMAsZtrRkbWJBEwAAAMzFmqJNOBMAAADMSIYtLVObcCYAAACYlzVFmwAAAABmJMOW0CYAAADYIkSbAAAAAJLIsCW0CQAAALYI0SYAAACAJDJsCW0CAACALUK0CQAAACCJDFtCmwAAAGCLEG0CAAAASCLDltAmAAAA2CJEmwAAAACSyLAltAkAAAC2CNEmAAAAgCQybAltAgAAgC1CtAkAAAAgiQxbQpsAAABgixBtAgAAAEgiw5bQJgAAANgiRJsAAAAAksiwJbQJAAAAtgjRJgAAAIAkMmwJbQIAAIAtQrQJAAAAIIkMW0KbAAAAYIsQbQIAAABIIsOW0CYAAADYIkSbAAAAAJLIsCW0CQAAALYI0SYAAACAJDJsCW0CAACALUK0CQAAACCJDFtCmwAAAGCLEG0CAAAASCLDltAmAAAA2CKXGG36fwIMgvnagrzPAAAAAElFTkSuQmCC
但我用下面代码测试能能够确认返回1至是10的list数据
效果:
>>>for i in range(1,10):print(i)
...
1
2
3
4
5
6
7
8
9
>>>

民国的课本 发表于 2022-3-10 08:13:15

range(1, 10)返回的是 ,不会把10也包括进去的

海上日出 发表于 2022-3-10 08:13:25

range不包括上限

时光碎片乱了夏 发表于 2022-3-10 08:13:38

1)range(1,10)没有返回list,如果需要返回list用:list(range(1,10))
2)range(a,b)返回数据返回a<=n<b,返回个数为b-a。
3)用户list=range(1,10),list是<range 'class'>
4)range(1,10)返回9

金海音乐工作室 发表于 2022-3-10 08:14:38

1、range()返回的是一个可迭代的 range类对象,并不是返回list啊,你是从哪儿听说返回的是list的啊?
>>> a = range(1, 10)
>>> type(a)
<class 'range'> # 返回了一个可迭代的range类对象
>>> list1 = []
>>> type(list1)
<class 'list'> # 只有当设定的是列表的时候,才会返回list类对象
2、 range()返回的元素个数是b-a, 本来就是这样啊,有什么问题嘛?

3、首先,这里的list本身属于python的保留字之一,不要把保留字用作变量名!重复:不要把保留字用作变量名!再有,返回class 'range'的问题我第一个回答已经告诉你是怎么回事了,这里的list是一个可迭代的range类对象,不是列表!

4、计算机序列是从0开始算第一个元素的,所以range(1, 10)当然就会返回 9 咯,因为第一个元素 1 在序列中的位置数是 0 啊
页: [1]
查看完整版本: 为什么range(1,10)函数没有返回list