Session 2: Python Lists And Loops

Hello everyone!

Use this thread to ask questions about topics covered in Session 2.

General rules to follow:

  • Indicate the quiz or exercise name at the beginning of your post.
  • Write down your question in as much detail as you possibly can.
  • If your question involves code, please include it in code blocks below with comments and avoid posting screenshots.

can you please explain what is the difference between reverse() and reversed() in list in a detailed way?

1 Like

Hi Swadesmita,

There are a few differences between the 2 functions.

The reverse() function is an inplace method. It will change the orginal list and return None.

Whereas, the reversed function will return a reversed list and not change the original list.

To understand this better you can play around with the following code.


list1 = [0,1,2,3,4,5,6]

list1_reversed = reversed(list1)

print("list1 reversed output : ", list(list1_reversed))

print("list1 original : ", list1)

list1_reverse = list1.reverse()

print("list1 reversed output : ", list1_reverse)

print("list1 original : ", list1)

Hope this helps.

1 Like

If you can’t see code block in the above post this is what it is supposed to be.

''list1 = [0,1,2,3,4,5,6]

list1_reversed = reversed(list1)

print("list1 reversed output : ", list(list1_reversed))

print("list1 original : ", list1)

list1_reverse = list1.reverse()

print("list1 reversed output : ", list1_reverse)

print("list1 original : ", list1)

β€˜β€™β€™

1 Like