1

I know conj(x) and x.conj() do the same thing, but what is the main difference?. Is that we can do any function as method such as sum(x) written as x.sum()?

AVI
  • 5,516
  • 5
  • 29
  • 38
jason
  • 1,998
  • 3
  • 22
  • 42

1 Answers1

1

If you are creating your own class you can define a method to use the built in function:

class Example(list):
    def sum(self):
        return sum(self)

x = Example((1,2,3))
print(x.sum())

Although there is no direct way to make this functionality available to built in types like list itself.

Tadhg McDonald-Jensen
  • 20,699
  • 5
  • 35
  • 59