0

I am new in python.

>>>li=["a","b","c"]
>>>li.reverse() 
>>>li
 ['c', 'b', 'a']

How we got an idea that we have to call function like this li.reverse() not like this reverse(li). Similarly on other function

sorted(li,reverse=True)
['c', 'b', 'a']

Here Why we can't call it li.sorted(reverse=True)?

Artier
  • 1,648
  • 2
  • 8
  • 22
  • Also https://stackoverflow.com/questions/3705670/best-way-to-create-a-reversed-list-in-python and https://stackoverflow.com/questions/3940128/how-can-i-reverse-a-list-in-python are relevant – DavidW Dec 03 '17 at 12:37
  • Because `reverse` is a method of list data-structure, while `sorted` is a builtin method (Not specific to any module or data-structure). You need to consult python official documentation to locate the right method and its correct usage. – Sohaib Farooqi Dec 03 '17 at 12:40

0 Answers0