Python MAGIC METHODS are easy! 🌟

  Рет қаралды 9,265

Bro Code

Bro Code

Күн бұрын

Пікірлер
@BroCodez
@BroCodez 4 ай бұрын
# 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___
@HojiakbarHabibullayev-jj6db
@HojiakbarHabibullayev-jj6db 3 ай бұрын
Hi bro thank you for lessons I like your you tube channel
@shirinMN
@shirinMN 11 күн бұрын
you are so amazing i like the way you teach and your voice too💯
@jankiwen3112
@jankiwen3112 4 ай бұрын
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.
@agyekumderrick9449
@agyekumderrick9449 4 ай бұрын
Bro to the world👊🏼, thanks for the updates all the time
@Hussain.115
@Hussain.115 4 ай бұрын
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.
@italianoconmohamed2233
@italianoconmohamed2233 3 ай бұрын
same here 😅
@oliya_b
@oliya_b 25 күн бұрын
Thank you for this clear explanation! You're such a good teacher! Thank you a lot😊
@vigneshs6842
@vigneshs6842 17 күн бұрын
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
@uzairzarry8691
@uzairzarry8691 4 ай бұрын
Great explanation❤
@matchalover08
@matchalover08 4 ай бұрын
Just started a new semester on algorithms, this posted at the right time for my revision! Thx bro!
@zedzpan
@zedzpan 4 ай бұрын
Love how you made this so simple to understand. Dunder methods were always weird to me!
@KnownUnknown5232
@KnownUnknown5232 4 ай бұрын
Bro you deserve way more likes
@ashwalker1
@ashwalker1 4 ай бұрын
Thank you Bro Can't wait for video on gaming channel
@nazihakh3517
@nazihakh3517 4 ай бұрын
you are awesome! thanks bro!
@nasiriqbal5475
@nasiriqbal5475 4 ай бұрын
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.
@MarianoBustos-i1f
@MarianoBustos-i1f 4 ай бұрын
Thanks Bro
@patrickjohnsanchez9427
@patrickjohnsanchez9427 4 ай бұрын
Bro Next video series please node js thanks bro
@JAYY1631
@JAYY1631 4 ай бұрын
he's awesome bro
@MFaiqVaince
@MFaiqVaince 4 ай бұрын
Can you plz update your c# playlist with more stuff after this, it will be very handy
@cbbcbb6803
@cbbcbb6803 3 ай бұрын
I really like your tutorials. But, I hate having to contort my fingers in order to key in special chaeacters!
@kapibara2440
@kapibara2440 4 ай бұрын
Great video, thank you🎉🎉🎉
@PriyanshModanwal
@PriyanshModanwal 4 ай бұрын
when will u drop the course ?
@FromTheWombTotheGrave
@FromTheWombTotheGrave 4 ай бұрын
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
@botpad4921
@botpad4921 4 ай бұрын
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😎😎
@vitavita5509
@vitavita5509 4 ай бұрын
bro thx
@Build33_Offical
@Build33_Offical 4 ай бұрын
L e g e n d
@ማዕዶት_tube
@ማዕዶት_tube 4 ай бұрын
Pls bro code❤❤❤😊
@rawa97775
@rawa97775 4 ай бұрын
Bro please a tutorial about discord python. Please bro code
@robert-qn8hy
@robert-qn8hy 4 ай бұрын
can you please make a video on python generators and asynchorous programming please
@samisalama3033
@samisalama3033 4 ай бұрын
Make a second 12 hour Python course.
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 60 МЛН
Why no RONALDO?! 🤔⚽️
00:28
Celine Dept
Рет қаралды 84 МЛН
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 97 МЛН
Увеличили моцареллу для @Lorenzo.bagnati
00:48
Кушать Хочу
Рет қаралды 8 МЛН
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 60 МЛН