__call__ in Python

  Рет қаралды 4,311

2MinutesPy

2MinutesPy

Күн бұрын

In this video, we will discuss the _call_ method and how to implement it in a class in Python.
When we invoke a function, we simply use the function name with parentheses(func()). This notifies the interpreter that a function is being called. Internally, it is equivalent to this expression func.__call__(), because functions in Python are objects and the call method is what gets executed when the function is invoked.
So, when we call a function in Python, the interpreter executes the _call_ method of the function object behind the scenes.
Chapters:
⏩ 0:00 Intro to _call_
⏩ 0:44 Basic example
⏩ 0:57 Where to use _call_ with example
⏩ 1:27 Real-life example
✨More on 2MinutesPy👇👇
▶️ Decorators in Python: • What are Decorators in...
▶️ List comprehension in Python: • How to use list compre...
▶️ How to use map() in Python: • How to use map() funct...
▶️ What is a Lambda Function in Python? • What is a Lambda Funct...
▶️ Why __init__.py File is Used in Python Projects: • Why __init__.py File i...
▶️ if _name_ == "__main__" in Python: • What if __name__ == '_...
▶️ Python's _init_ Method in 2 Minutes: • Python's __init__ Meth...
Subscribe to / @2minutespy for more such videos.
@2MinutesPy
#class #method #objectorientedprogramming #oop #python

Пікірлер: 24
@sebastianmorales9787
@sebastianmorales9787 19 күн бұрын
Never seen this before. First half of the video I was like 'ok, another dunder method, so what', then the example with the API makes all the sense in the world... Thanks!
@2MinutesPy
@2MinutesPy 18 күн бұрын
Nice 👍
@LootBoxLegendsYT
@LootBoxLegendsYT 18 күн бұрын
@@2MinutesPythen why should not that call to api go to constructor or a diff method?
@spidey2468
@spidey2468 18 күн бұрын
Never ever a day goes when I feel how underrated this channel is , Pls start a series on something around this ❤
@2MinutesPy
@2MinutesPy 17 күн бұрын
Thanks, sure
@youngsci
@youngsci 12 күн бұрын
I have been looking for a Python daily refresher, and thankfully, I found your channel. Thank you for the high-quality, short, and informative videos.
@2MinutesPy
@2MinutesPy 12 күн бұрын
Glad it was helpful!
@10uRization
@10uRization 13 күн бұрын
The most underrated Python channel
@2MinutesPy
@2MinutesPy 12 күн бұрын
Thanks for the support
@dweepverma3662
@dweepverma3662 16 күн бұрын
I really want this video to go viral, it's just great 👍. Thank you 2minutespy
@2MinutesPy
@2MinutesPy 16 күн бұрын
Thank you bro
@maxpythoneer
@maxpythoneer 16 күн бұрын
Nice one😊❤
@2MinutesPy
@2MinutesPy 16 күн бұрын
Thanks
@pedrohfahrenheit7347
@pedrohfahrenheit7347 3 күн бұрын
It's a great channel. I routinely struggle when I'm studying programming, because I can't grasp the content well when I don't get the background of it. Knowing how a bit of it works is, as someone in the comments already said, refreshing! There is some specific name for those aspects and processes that happen behind the scenes in Python? I would like to search it more profoundly by myself (Sorry for any English misspelling, learning yet)
@hackytech7494
@hackytech7494 19 күн бұрын
Thank you so much for this video 🙏❤
@2MinutesPy
@2MinutesPy 18 күн бұрын
Most welcome 😊
@krzysiekkrzysiek9059
@krzysiekkrzysiek9059 20 күн бұрын
Finally bro. Thx 👌
@2MinutesPy
@2MinutesPy 19 күн бұрын
Much welcome
@DavidZammit
@DavidZammit 19 күн бұрын
Nice one! Short clear and useful learning video = Subscribed! Just to confirm my understanding- you could have made a function inside the class (eg callAPI) and call it like this: response = client.callAPI("users", id=123), but this dunder call is the easy to use/shortcut version of the same, by having a default function (__call__) be called directly? No other real change I presume?
@2MinutesPy
@2MinutesPy 18 күн бұрын
Yes, you are right
@ombiradar1969
@ombiradar1969 20 күн бұрын
So the dunder call can be used as a constructor for a class too?
@2MinutesPy
@2MinutesPy 19 күн бұрын
No, this ain't true. The dunder call can be used to make instances of the class callable like function. for example: `hello = Hello()` - Now wen can make `hello` instance callable like this `hello()` and pass arguments if the dunder call is defined within the `Hello` class.
@compositeboson123
@compositeboson123 20 күн бұрын
bro got caught to the web 💀
@2MinutesPy
@2MinutesPy 19 күн бұрын
ha, really!
5 Good Python Habits
17:35
Indently
Рет қаралды 430 М.
THEY made a RAINBOW M&M 🤩😳 LeoNata family #shorts
00:49
LeoNata Family
Рет қаралды 38 МЛН
Can You Draw A PERFECTLY Dotted Circle?
00:55
Stokes Twins
Рет қаралды 40 МЛН
Scary Teacher 3D Nick Troll Squid Game in Brush Teeth White or Black Challenge #shorts
00:47
Python Generators
15:32
mCoding
Рет қаралды 132 М.
The 3 Laws of Writing Bug Free Code
3:59
Kantan Coding
Рет қаралды 47 М.
How To Use List Comprehension In Python
6:41
Taylor's Software
Рет қаралды 6 М.
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 648 М.
*Args and **Kwargs in Python
3:49
b001
Рет қаралды 255 М.
5 Cool Python One-Liners
12:23
Indently
Рет қаралды 30 М.
5 Useful Python Decorators (ft. Carberra)
14:34
Indently
Рет қаралды 92 М.
Modern Python logging
21:32
mCoding
Рет қаралды 162 М.
15 Python Libraries You Should Know About
14:54
ArjanCodes
Рет қаралды 373 М.
__new__ VS __init__ in Python
2:35
2MinutesPy
Рет қаралды 4 М.
😱Хакер взломал зашифрованный ноутбук.
0:54
Последний Оплот Безопасности
Рет қаралды 703 М.
iPhone 15 Pro в реальной жизни
24:07
HUDAKOV
Рет қаралды 334 М.
Samsung Galaxy 🔥 #shorts  #trending #youtubeshorts  #shortvideo ujjawal4u
0:10
Ujjawal4u. 120k Views . 4 hours ago
Рет қаралды 6 МЛН
Где флагманы с IPS?
0:52
Не шарю!
Рет қаралды 66 М.
Easy Art with AR Drawing App - Step by step for Beginners
0:27
Melli Art School
Рет қаралды 13 МЛН