Search notes:

Python: method (type)

class cls:

  def __init__(self, m1):
        self.m1 = m1

  def f(self, m2):
        print(f'm1: {self.m1}, m2: {m2}')


obj = cls(7)

obj_f = obj.f
cls_f = cls.f

print(type(obj_f))
#
#  <class 'method'>

print(type(cls_f))
#
#  <class 'function'>

print(obj_f.__self__  is obj  )
#
#  True

print(obj_f.__func__  is cls_f)
#
#  True

obj_f(4)
#
#  m1: 7, m2: 4
Github repository about-Python, path: /types/method/demo.py

See also

Other Built-in types such as builtin_function_or_method or function.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758203805, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/types/method/index(70): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78