Discuss / Python / 有个问题想请教一下

### 有个问题想请教一下

Topic source

#### G好大的鱼

#1 Created at ... [Delete] [Delete and Lock User]

``````L=list(range(100))
``````

``````L=[range(100)]
``````

#### 廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

#### G好大的鱼

#3 Created at ... [Delete] [Delete and Lock User]

L=list(range(10)) print出来是[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

L=[range(10)] print出来是[range(0, 10)]

#### 廖雪峰

#4 Created at ... [Delete] [Delete and Lock User]

#### Dreamer_DK

#5 Created at ... [Delete] [Delete and Lock User]

``````list(range(10))
``````

``````range(10)
``````

#### 罐罐姥爷

#6 Created at ... [Delete] [Delete and Lock User]

for i in range(0,10): print(i) 和 i=list(range(10)) print(i) 那他们的结果算一样的吗？

#### tt1296116093

#7 Created at ... [Delete] [Delete and Lock User]
``````>>> list_1 = list(range(100))
>>> list_1
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
>>> list_2 = [range(100)]
>>> list_2
[range(0, 100)]
>>> list_2[0][1]
1
``````

``````list(range(100))
``````

list_2 即

``````[range(100)]
``````

``````[range(100),元素2,元素3,,,,,]
``````

#### Lancer听从ken的召唤前来

#8 Created at ... [Delete] [Delete and Lock User]

L=list(range(10)) print出来是[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 这里是把range(10)的10个数形成一个列表list，然后赋值给L

L=[range(10)] print出来是[range(0, 10)] 这里是range（10）作为L这个list的一个元素

#### iSilent94021

#9 Created at ... [Delete] [Delete and Lock User]
``````在此插入代码
for i in range(0,10):
print(i)
``````

``````>>> for i in range(0,10):
...     print(i)
...
0
1
2
3
4
5
6
7
8
9
>>> i = list(range(10))
>>> print(i)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
``````

• 1