Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python Callables

# Functions and classes are both callables, but you can actually invent your own callable objects too.

# We have a class here called Person:

class Person:
    def __init__(self, name):
        self.name = name
    def __call__(self):
        print("My name is", self.name)
# Classes are callable and we call the Person class to get back an instance of that class:

>>> trey = Person("Trey")
>>> trey
<__main__.Person object at 0x7fbf9f3331c0>
# But the Person object is also callable! We can call that Person object by putting parentheses after it:

>>> trey()
My name is Trey
# This works because we've implemented a __call__ method on the Person class. Adding a __call__ method to a class makes its class instances callable.
Comment

Python Callables

User-Defined Functions
Generators
Classes
Instance Methods
Class Instances (__call__())
Built-in Functions (e.g. len(), open())
Built-in Methods (e.g. my_list.append(x))
Comment

PREVIOUS NEXT
Code Example
Python :: threading pass keyword args example 
Python :: using return values python script in batch script 
Python :: accessing list elements in python 
Python :: Count the number of Missing Values in the DataFrame 
Python :: axios post to django rest return fobidden 403 
Python :: how to remove hidden white spaces n columns 
Python :: Python Tkinter Message Widget Syntax 
Python :: check if varible is emyt pyton 
Python :: difference_update() Function of sets in python 
Python :: Adding new nested object using Shallow copy 
Python :: how to use print function in python stack overflow 
Python :: get column means pandas 
Python :: Mirror Inverse Program in python 
Python :: find if string is substring of another 
Python :: python variable and data structure 
Python :: python enum key string get 
Python :: enter three numbers and find smallest number in python 
Python :: how to install pygame for python 3.8.5 
Python :: manim replacement transform 
Python :: python basic programs quadratic equation 
Python :: Source code: Matrix Addition using Nested Loop 
Python :: generator expression python 
Python :: how to compare the two key from constant value to list of string in python 
Python :: how to use ttk themes 
Python :: cos2x 
Python :: scatter plot actual vs predicted python 
Python :: io.imsave 16 bit 
Python :: how to element into the first index python 
Python :: dont print pip jupyter 
Python :: RC style Relative Referencing in OpenPyXL 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =