What is a method and when use a method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is a method and when use a method

1st Oct 2019, 7:06 PM
Balaji
Balaji - avatar
5 Answers
+ 2
A method is a function that belongs to an object. Use it when you want to do something with the object.
1st Oct 2019, 7:08 PM
Airree
Airree - avatar
+ 2
Oh found one "In Python, a method is a function that is available for a given object because of the object's type. For example, if you create my_list = [1, 2, 3] , the append method can be applied to my_list because it's a Python list: my_list.append(4) . All lists have an append method simply because they are lists"
2nd Oct 2019, 7:33 PM
Tim
+ 1
Methods are useful becaude they: ~make code more readable ~prevent name conflicts ~help separating different tasks for different objects
1st Oct 2019, 8:20 PM
Seb TheS
Seb TheS - avatar
0
Examples pls
2nd Oct 2019, 7:27 PM
Tim
0
Timour Zinaliyev Yes, and if there was another datatype, such as set, that also would have had an append method, no name conflicts would happen due that.
2nd Oct 2019, 7:59 PM
Seb TheS
Seb TheS - avatar