Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

staticmethod vs classmethod python

# With classmethods, the class of the object instance is
# implicitly passed as the first argument instead of self.

class A(object):
    def foo(self, x):
        print(f"executing foo({self}, {x})")

    @classmethod
    def class_foo(cls, x):
        print(f"executing class_foo({cls}, {x})")

    @staticmethod
    def static_foo(x):
        print(f"executing static_foo({x})")

a = A()
Comment

PREVIOUS NEXT
Code Example
Python :: numpy if zero is present 
Python :: how to install python packages in local directory 
Python :: rank function in pandas 
Python :: how to loop function until true python 
Python :: Python NumPy stack Function Example with 1d array 
Python :: jacobi iteration method python 
Python :: state capitals python 
Python :: mistborn series 
Python :: binary search tree implementation in python 
Python :: tkinter insert value box 
Python :: decode a qrcode inpython 
Python :: access cmd with python 
Python :: smallest possible number in python 
Python :: how to put my graph in tkinter interface 
Python :: websocket api python on close 
Python :: python game github 
Python :: add element to array list python 
Python :: python re.findall() 
Python :: python selenium click on agree button 
Python :: run python test in terminal 
Python :: python lock file 
Python :: cv2.imshow not working in vscode 
Python :: python default value 
Python :: iloc pandas 
Python :: webpage with aiohttp 
Python :: string in python 
Python :: python types of loops 
Python :: switch case python 3.10 
Python :: how to draw dendrogram in python 
Python :: dimension of an indez pandas 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =