+ 7
Why we use this in python?
1. x=[1,3,2,4] 2. x.sort() 3. print(x),can you tell me why we use parentheses after write sort in line 2,why we use these parentheses to write many methods.
3 odpowiedzi
+ 6
Because attributes are a thing. For example:
class Car:
def __init__(self, color):
self.color = color
car = Car("red")
car.color # this value is "red"
If methods were without parentheses, it would be hard to distinguish between an attribute and a method (car.color and car.color(), for example).
Some languages do have parenthesesless methods, like Ruby, but I find that less readable. Even so, you can use parentheses if you want.
+ 4
We use parentheses for methods to differentiate them from variables.
0
Hello Maninder
As Say Vlad sort() is a method or function.
We use sort() in these langages:javascript,php..
it displays your result in order(alphabetical too)
sort() is different than reverse()
Bye