Thank you so much! I've been seeing those weird double underscores in so many other tutorials (completely unrelated to dunder methods) but only now have I found a video explaining them in such an approachable way. Python is my favorite programming language, I'm glad to learn it more thoroughly.
Basically we are using method overriding with built in methods. For example. > op will take either str or int , but we are overriding the method to compare object attributes
Thankgod after spending 2 days now I got what actually these methods are 😊 after watching many videos from different channels its okay to check other sources.
Brooooo, what did you study in college? only Computer Science or other extensive subjects too? Btw i learnt python from you and am currently learning html and css, thank you bro, bootcamps hate you fr.
Can u make vid about Python AI bot creations/LLMs And automations with AI Creating videos with AI in Python Or automated instagram theme page run by AI
bro, i have learned web dev from ur playlist, but now i need a course for certificates, can u tell me what to do for the certificates? btw ur videos are too good fr😎😎
# Magic methods = Dunder methods (double underscore) ___init__, __str__, __eq___
# They are automatically called by many of Python's built-in operations.
# They allow developers to define or customize the behavior of objects
class Book:
def __init__(self, title, author, num_pages):
self.title = title
self.author = author
self.num_pages = num_pages
def __str__(self):
return f"'{self.title}' by {self.author}"
def __eq__(self, other):
return self.title == other.title and self.author == other.author
def __lt__(self, other):
return self.num_pages < other.num_pages
def __gt__(self, other):
return self.num_pages > other.num_pages
def __add__(self, other):
return f"{self.num_pages + other.num_pages} pages"
def __contains__(self, keyword):
return keyword in self.title or keyword in self.author
def __getitem__(self, key):
if key == "title":
return self.title
elif key == "author":
return self.author
elif key == "num_pages":
return self.num_pages
else:
return f"Key '{key}' was not found"
book1 = Book("The Hobbit", "J.R.R. Tolkien", 310)
book2 = Book("Harry Potter and The Philosopher's Stone", "J.K. Rowling", 223)
book3 = Book("The Lion, the Witch and the Wardrobe", "C.S. Lewis", 172)
print(book1) # Calls ___str___
print(book1 == book3) # Calls ___eq___
print(book1 < book2) # Calls ____lt___
print(book2 > book3) # Calls ___gt___
print(book1 + book2) # Calls ___add___
print("Lion" in book3) # Calls ___contains___
print(book3['title']) # Calls ___getitem___
Hi bro thank you for lessons I like your you tube channel
Thank you so much! I've been seeing those weird double underscores in so many other tutorials (completely unrelated to dunder methods) but only now have I found a video explaining them in such an approachable way. Python is my favorite programming language, I'm glad to learn it more thoroughly.
Thank you for this clear explanation! You're such a good teacher! Thank you a lot😊
Bro to the world👊🏼, thanks for the updates all the time
Basically we are using method overriding with built in methods. For example. > op will take either str or int , but we are overriding the method to compare object attributes
Thankgod after spending 2 days now I got what actually these methods are 😊 after watching many videos from different channels its okay to check other sources.
same here 😅
Just started a new semester on algorithms, this posted at the right time for my revision! Thx bro!
Love how you made this so simple to understand. Dunder methods were always weird to me!
Bro you deserve way more likes
Great explanation❤
you are awesome! thanks bro!
Thank you Bro Can't wait for video on gaming channel
Brooooo, what did you study in college? only Computer Science or other extensive subjects too? Btw i learnt python from you and am currently learning html and css, thank you bro, bootcamps hate you fr.
I really like your tutorials.
But, I hate having to contort my fingers in order to key in special chaeacters!
Thanks Bro
Can you plz update your c# playlist with more stuff after this, it will be very handy
when will u drop the course ?
Bro Next video series please node js thanks bro
Can u make vid about Python AI bot creations/LLMs
And automations with AI
Creating videos with AI in Python
Or automated instagram theme page run by AI
Great video, thank you🎉🎉🎉
he's awesome bro
bro, i have learned web dev from ur playlist, but now i need a course for certificates, can u tell me what to do for the certificates? btw ur videos are too good fr😎😎
bro thx
L e g e n d
Pls bro code❤❤❤😊
Bro please a tutorial about discord python. Please bro code
can you please make a video on python generators and asynchorous programming please
Make a second 12 hour Python course.