Learn Before
Concept

Methods vs. Functions

A method is a function that is explicitly tied to a class. Unlike regular functions, methods require an object instance of the class it is tied to in order to be called.

class MyClass: def __init__(self, n, a): selt.name = n self.age = a def myName(self): print(self.name) myName() # This method cannot be called on its own Jim = MyClass("Jim", 25) Jim.myName() # This call works

0

1

Updated 2021-02-09

Tags

Python Programming Language

Data Science