+ 7

What's the difference between functions and methods in python?

29th Aug 2019, 11:20 AM
Byk
2 Answers
+ 6
I also find out there's is a difference in calling. To call a function we pass like an argument. Function call: a = "Hello" print (a) Method call: To call a method we use dot operator as follows a.lower () #makes every character lower case
29th Aug 2019, 12:37 PM
Byk
+ 2
Methods are functions that are associated with a class. The most common use case is that every instance of that class can use these methods - as if you press a button on a tool. Let's look at a method of the builtin class 'list': a = [3, 5, 1] b = ['h', 'g', 'z'] a.sort() b.sort() So you can press the 'sort button' (use the sort method) on both the different lists, that even contain different stuff. And it works - a will be sorted from lowest to highest, b alphabetically.
29th Aug 2019, 12:30 PM
HonFu
HonFu - avatar