Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are "class functions" referred to as "functions" or "methods" in Python

See the code below

class HelloWorld:
    def print(self):
        print "Hello World"

Is HelloWorld.print(self) called a method or a function in Python?

like image 774
Ztyx Avatar asked May 02 '26 20:05

Ztyx


2 Answers

They are referred to as class methods or instance methods.

like image 58
Jakob Bowyer Avatar answered May 05 '26 11:05

Jakob Bowyer


Just to add to Jakob's clear answer, in languages like Python there is no requirement that everything lives within a class, unlike (say) Java. So whereas in Java every function is a method, in Python this isn't true: many or even most functions aren't part of a class. That's why it makes sense to have this terminology distinction between methods and functions.

like image 23
Daniel Roseman Avatar answered May 05 '26 10:05

Daniel Roseman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!