Revising the Difference between Methods and Functions

What's the difference between a function and a method?

In python everything is an object A method gets invoked on a given Object

mylist = [1,2,3,4]
mylist.pop()

A function does not get invoked on a given Object, it exists on it's own

maxvalue = max([1,2,3,4])
print(maxvalue)

A function cannot be invoked before it was defined:

myname()

def myname():
	print("imtiaz")

What is OOP?

  • It is a way to organize the code better rather than keeping everything in one file

  • Dumping everything in a single file would be very difficult to manage, so OOP allows you to keep a structure and a logical narative

  • OOP allows us to re-use code that we have already written

  • Break things into chunks and using multiple files

Last updated