Magic/Dunder Methods in Python | Python Tutorial - Day #73

preview_player
Показать описание

python, C, C++, Java, JavaScript and Other Cheetsheets [++]:

►Learn in One Video[++]:

►Complete course [playlist]:

Follow Me On Social Media
Comment "#HarryBhai" if you read this 😉😉
Рекомендации по теме
Комментарии
Автор

Quick Quiz Answer
class shop:
def __init__(self, sales, expenditure):
self.sales=sales
self.expenditure=expenditure
def __call__(self):
print(F"The total profit is
shop1=shop(15000, 12000)
shop1()
Output:
The total profit is 3000

ankushsingh
Автор

I have never been this consistent with my learning enjoying every minute of this course

i_am_dumb
Автор

quickquiz answer🔥🔥🔥

__call__ can be used in a same fasion as help() like to descripe an object and its properties in a readable format

technomusiccloud
Автор

I think the practicle use case of def__call__(self ) : method will be to add conclusion to a class or it can used to find total amount at the end of class

irfanmohammad
Автор

Call method can be used to use a class instance like a function. We can give arguments and executes it however we want

ahsantariq
Автор

Reached #day 73 and realllyy enjoying each day and gaining knowledge :) Harry sir you are

swatidixit
Автор

Very good and informative content.... This is the most user friendly and learner friendly tutorial channel. Harry bhai 9999 kilo shukriya...

theankitsagarit
Автор

Harry bhai plz start a machine learning ultimate course too from beginner to advanced really need it 🙏🏼🙏🏼

probalkar
Автор

call function practical use might be to check the functions in the element

sanjeevthakur
Автор

QUICK QUIZ ANSWER:
class calculator:
def __init__(self, base):
self.base = base

def __call__(self, x):
return self.base + x

c = calculator(10)
print(c(5))

rahmansherif
Автор

bro we can actually use the printing of length of name by print(len(e.name))

mohankilari
Автор

__call__() Method is used to make the instance of class object callable.

class Callable:
def __call__(self):
return "Instance is Callable"

instance = Callable()
print(callable(instance)) #return True if callable
instance() #calling the instance

mehmoodahmed
Автор

Quick Quiz: Harry sir in the short time I only found this little application of the __call__ under method:

import random
import string


class Employee:
def __init__(self, name) -> None:
self.name = name

def __call__(self, *args, **kwargs): # this makes the instance callable
self.id = "".join(
random.choices(self.name + string.ascii_letters + string.digits, k=6)
)
print(f"The Employee's ID: {self.id}")


e = Employee("Arpan")
e()

# The dunder/magic method __call__ here, prints the Employee's randomly generated 6 character ID

arpankarmakar
Автор

Harry bhi, you've unnecessarily complicated this lecture, and I needed to understand it from Jenny's lecture.

HuzaifaKhan-iyqj
Автор

I think the practical use case of def__call__(self ) : is to add a definition or conclusion of a class which can easily be obtained

regulusblack
Автор

Prctical use case might be to use the class as an argument to The Function like it may return a list which can be used as a argument in a funcion

sasticoaching
Автор

At 7:45 why is it executing only the str method and not the repr method . Even though we have not called either of them while typing print(e). Can anyone help 🙏

veersinghchauhan
Автор

But sir, we can print the len of name like :
# Coding :
class Employee:
name = "harry"
# def __len__(self):
# i = 0
# for c in self.name:
# i += 1
# return i

e = Employee()
print(e.name)
# print(len(e))

print(len(e.name))

AbdulHadi-qqhp
Автор

Harry bhaiya, I request you... Aap please apne interpreter ka size bada rakha kare. Or console ko small size me rakhe take dekhne me or samajh ne aasani ho...

Thank for teach us.

LogicOfComputerScience
Автор

10:40 to know don't of the major details of class or every object of class or get the information of class

saradasarawagi