Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list vs [] with range
#2
You are correct. The first one has a single object in the list, the second one is the expansion of the range and has the ints inside.

>>> len([range(9)])
1
>>> type([range(9)][0])
<class 'range'>
>>> len(list(range(9)))
9
Reply


Messages In This Thread
list vs [] with range - by quazirfan - Sep-19-2020, 01:21 AM
RE: list vs [] with range - by bowlofred - Sep-19-2020, 03:31 AM
RE: list vs [] with range - by deanhystad - Sep-19-2020, 03:33 AM
RE: list vs [] with range - by perfringo - Sep-19-2020, 05:30 AM
RE: list vs [] with range - by scidam - Sep-19-2020, 03:41 AM
RE: list vs [] with range - by deanhystad - Sep-19-2020, 12:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Down I hate "List index out of range" Melen 20 3,353 May-14-2023, 06:43 AM
Last Post: deanhystad
  IndexError: list index out of range dolac 4 1,924 Jul-25-2022, 03:42 PM
Last Post: deanhystad
  IndexError: list index out of range Anldra12 2 1,449 May-03-2022, 01:39 PM
Last Post: Anldra12
  TypeError: list indices must be integers or slices, not range Anldra12 2 2,591 Apr-22-2022, 10:56 AM
Last Post: Anldra12
  matplotlib x axis range goes over the set range Pedroski55 5 3,230 Nov-21-2021, 08:40 AM
Last Post: paul18fr
  IndexError: list index out of range rf_kartal 6 2,863 Sep-07-2021, 02:36 PM
Last Post: Larz60+
  Python Error List Index Out of Range abhi1vaishnav 3 2,325 Sep-03-2021, 08:40 PM
Last Post: abhi1vaishnav
  IndexError: list index out of range Laplace12 1 2,233 Jun-22-2021, 10:47 AM
Last Post: Yoriz
  IndexError: list index out of range brunolelli 11 6,579 Mar-25-2021, 11:36 PM
Last Post: brunolelli
  IndexError: list index out of range ramu4651 2 3,758 Jan-24-2021, 01:45 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020