A method in Python is similar to a function, in that it allows us to do things with data. However, a method is attached to what we call an object, which is a representation of data. Accordingly, a method operates as a function that is specifically available for that object.
Methods are accessed through the dot syntax .
. For example, the method lower()
can be attached to a string object like so: "HELLO".lower()
and will return the string 'hello'
.
-
Read about the difference between a method and a function on Tutorials Point.
-
If you know something about classes and are ready to jump deeper into Object Oriented Programming, you can learn more about methods and classes on Data Flair.