What is the difference between inline methods and inline functions? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the difference between inline methods and inline functions?

Question Pyhon3

16th Dec 2019, 9:05 AM
Aitodev
Aitodev - avatar
2 Answers
+ 2
To understand what inline methods and inline functions are, first you need to understand what are the differences between methods and functions. A functions is just a command to make Python do something. It can be user defined or pre-built. They can be called on their won and they have their own characteristics. They can be called whenever you want. For example: def car(): print("Vroom") But methods are a bit different. They are called on objects, which are representatives of classes. For example: class Calculator: # create addNumbers static method @staticmethod def multiplyNums(x, y): print(x * y) A = Calculator() A.multiplyNums(2, 3) In this case, multiplyNums is a method as it is called on the 'A' object. So if you understand this difference, you can figure out the differences between inline ones.
16th Dec 2019, 9:50 AM
Ahnaf
Ahnaf - avatar
+ 1
All methods are functions. Not all functions are methods. Methods are functions that belong to (are defined inside) a class. functions are called as: function(args) methods are called as: object.function(args) which means the method is passed the object as first parameter (a.k.a. "self"), followed by your arguments (if any). for this reason, methods can obviously be public, private or protected while other functions are pretty much defined in the global scope. and yes - everything in python is an object (even functions), which is why you use methods all the time.
17th Dec 2019, 5:44 AM
grdr