Python Forum
Question about List.reverse() method
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about List.reverse() method
#1
CountDown=[1, 2, 3]
print(CountDown.reverse())

When I run above scripts, I got the result: None instead of [3, 2, 1]
Could anyone explain to me why? Thanks.
Reply
#2
As the documentation tells you (e.g. help(list.reverse) in the REPL), the method reverses in place (i.e. doesn't produce a new list). If you want a new value then, use reversed, but do note that it produces an iterator.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 1,306 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  Unable to use random.choice(list) in async method spacedog 4 3,418 Apr-29-2021, 04:08 PM
Last Post: spacedog
  About list and method .... Fernando_7obink 3 2,289 Dec-22-2020, 09:15 AM
Last Post: Fernando_7obink
  while loop reading list in reverse Jerry51 1 1,565 Apr-24-2020, 12:44 PM
Last Post: deanhystad
  print all method and property of list object engmoh 4 2,842 Oct-26-2019, 05:33 PM
Last Post: engmoh
  Reverse list items in a stupid way pyth0n123 4 2,639 Jul-28-2019, 02:52 PM
Last Post: pyth0n123
  sqlite3 question - execute method with :parameter richalt2 2 7,466 May-20-2019, 05:35 PM
Last Post: woooee
  reverse list, incl. nested list Livne_ye 3 3,136 May-04-2019, 12:34 PM
Last Post: Livne_ye
  why my method doesn't find my List in the same class? Scorpio 2 2,378 Jan-31-2019, 05:21 PM
Last Post: Scorpio
  about List question longmail 2 2,349 Nov-30-2018, 02:08 AM
Last Post: longmail

Forum Jump:

User Panel Messages

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