Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use a class and when should I use a function?

Tags:

python

When is a class more useful to use than a function? Is there any hard or fast rule that I should know about? Is it language dependent? I'm intending on writing a script for Python which will parse different types of json data, and my gut feeling is that I should use a class to do this, versus a function.

like image 697
Steven Matthews Avatar asked Dec 06 '22 13:12

Steven Matthews


1 Answers

You should use a class when your routine needs to save state. Otherwise a function will suffice.

like image 177
Ignacio Vazquez-Abrams Avatar answered Dec 31 '22 13:12

Ignacio Vazquez-Abrams