当前位置:网站首页>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()

边栏推荐
- General process after reference layer reboot
- Review of drug discovery-02-prediction of molecular properties
- Li Kou today's question -522 Longest special sequence
- What is digitalization? What is digital transformation? Why do enterprises choose digital transformation?
- Intensive reading of transformer thesis paragraph by paragraph
- MySQL十种锁,一篇文章带你全解析
- Cesium 点击绘制多边形(动态绘制多边形)
- Deep parsing of kubernetes controller runtime
- 药物发现综述-02-分子性质预测
- Is it safe to open an online futures account?
猜你喜欢

Web3 technology initial experience and related learning materials

什麼是數字化?什麼是數字化轉型?為什麼企業選擇數字化轉型?

Self supervised learning and drug discovery

MapReduce elementary programming practice

What is digitalization? What is digital transformation? Why do enterprises choose digital transformation?

The practice of dual process guard and keeping alive in IM instant messaging development

声网 VQA:将实时互动中未知的视频画质用户主观体验变可知

基于可学习尺寸自适应分子亚结构的药物相互作用预测

Data analysts too hot? Monthly income 3W? Tell you the true situation of this industry with data

Numpy----np.tile()函数解析
随机推荐
PV operation primitive
General process after reference layer reboot
MapReduce elementary programming practice
PV操作原语
Hi, you have a code review strategy to check!
766. 托普利茨矩阵
Adobe Premiere基础-声音调整(音量矫正,降噪,电话音,音高换挡器,参数均衡器)(十八)
Adobe Premiere Basics - common video effects (cropping, black and white, clip speed, mirroring, lens halo) (XV)
Chapitre 4: redis
嵌入式必学,硬件资源接口详解——基于ARM AM335X开发板 (上)
Prometeus 2.35.0 新特性
9. Openfeign service interface call
深入解析kubernetes controller-runtime
【sylixos】i2c设备驱动创建和使用
面试官问:JS的继承
Supervised, unsupervised and semi supervised learning
Lmsoc: a socially sensitive pre training method
Google Earth engine (GEE) -- an error caused by the imagecollection (error) traversing the image collection
pytorch_lightning.utilities.exceptions.MisconfigurationException: You requested GPUs: [1] But...
数据库的新选择 Amazon Aurora