当前位置:网站首页>Class initialization and callback usage
Class initialization and callback usage
2022-06-28 02:07:00 【Rookies should love learning】
Learning goals :
Distinguish correctly Class initialization and callback
About class initialization
class A():
def __init__(self):
print('Hello, world!')
A()

Calls to classes
class A():
def __call__(self):
print('hello,world!!!!!!!!!!!!!!')
a = A()
a()

This is it. __init__ And __call__ The difference in usage !
About their specific application in programming
Example 1
class A():
def __init__(self):
print('hello,world!')
def __call__(self):
print('hello,world!!!!!!!!!!!!!')
a = A()
a()

Example 2
class A():
def __init__(self, init_age):
print(' My age is :', init_age)
self.age = init_age
def __call__(self, added_age):
res = self.forward(added_age) # call forward function
return res
def forward(self, input_):
print('forward Function called ')
return input_ + self.age
print(' Object initialization ………………')
a = A(16)
input_param = a(2)
print(" My age now will always be :", input_param)

Example 3
class Animal():
def __init__(self,name):
self.name = name
def greet(self):
print('animal is {}'.format(self.name))
class Cat(Animal):
def greet(self):
super(Cat, self).greet()
print("It's name is wangwang")
a=Cat('cat')
a.greet()

边栏推荐
- 基于AM335X开发板 ARM Cortex-A8——Acontis EtherCAT主站开发案例
- 外盘期货哪里可以开户?哪个平台出入金比较安全?
- Overview of drug discovery-01 overview of drug discovery
- 如何高效读书学习
- 【嵌入式基础】内存(Cache,RAM,ROM,Flash)
- 什么是数字化?什么是数字化转型?为什么企业选择数字化转型?
- Web3 technology initial experience and related learning materials
- 一张图弄懂 MIT,BSD,Apache几种开源协议之间的区别
- 学习 pickle
- Appium自动化测试基础 — ADB常用命令(一)
猜你喜欢

嵌入式必学,硬件资源接口详解——基于ARM AM335X开发板 (上)

【牛客讨论区】第四章:Redis

766. toplitz matrix

Implementation of timed tasks in laravel framework

Voice network VQA: make the user's subjective experience of unknown video quality in real-time interaction known

利用redis bitmap实现人员在线情况监控

树莓派实现温控风扇智能降温

Neural network of zero basis multi map detailed map

How to understand query, key and value in transformer

How fiddle uses agents
随机推荐
Transformer论文逐段精读
评价——灰色关联分析
基于AM335X开发板 ARM Cortex-A8——Acontis EtherCAT主站开发案例
[Yongyi XY chair] trial experience
Some problems in awk
Overview of drug discovery-01 overview of drug discovery
PV operation primitive
向excel中导入mysql中的数据表
Supervised, unsupervised and semi supervised learning
Chapitre 4: redis
Database query optimization: master-slave read-write separation and common problems
Réseau neuronal pour la solution détaillée Multi - diagrammes de fondation zéro
【嵌入式基础】内存(Cache,RAM,ROM,Flash)
Interviewer asked: Inheritance of JS
Using redis bitmap to realize personnel online monitoring
[Yocto RM] 4 - Source Directory Structure
评价——秩和比综合评价
Lefse analyzes the local implementation method with all installation files and details to ensure success.
基于可学习尺寸自适应分子亚结构的药物相互作用预测
如何阅读一篇论文