Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list vs [] with range
#1
Hello, I am just learning python so bear with me.

I am trying to figure out why the output of the following two lines are different despite both of them returning a list.

In: [range(9)]
Out: [range(0, 9)]
In: list(range(9))
Out: [0, 1, 2, 3, 4, 5, 6, 7, 8]

In: type([range(9)])
Out: list
In: type(list(range(9)))
Out: list

I am guessing for the 2nd approach I am passing a range object in a list constructor. Is my guess corrcet?
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,157 May-14-2023, 06:43 AM
Last Post: deanhystad
  IndexError: list index out of range dolac 4 1,843 Jul-25-2022, 03:42 PM
Last Post: deanhystad
  IndexError: list index out of range Anldra12 2 1,408 May-03-2022, 01:39 PM
Last Post: Anldra12
  TypeError: list indices must be integers or slices, not range Anldra12 2 2,500 Apr-22-2022, 10:56 AM
Last Post: Anldra12
  matplotlib x axis range goes over the set range Pedroski55 5 3,103 Nov-21-2021, 08:40 AM
Last Post: paul18fr
  IndexError: list index out of range rf_kartal 6 2,761 Sep-07-2021, 02:36 PM
Last Post: Larz60+
  Python Error List Index Out of Range abhi1vaishnav 3 2,236 Sep-03-2021, 08:40 PM
Last Post: abhi1vaishnav
  IndexError: list index out of range Laplace12 1 2,186 Jun-22-2021, 10:47 AM
Last Post: Yoriz
  IndexError: list index out of range brunolelli 11 6,346 Mar-25-2021, 11:36 PM
Last Post: brunolelli
  IndexError: list index out of range ramu4651 2 3,693 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