Python MAGIC METHODS are easy! 🌟

  Рет қаралды 14,153

Bro Code

Bro Code

Күн бұрын

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
#python #pythontutorial #pythonprogramming

Пікірлер: 39
@BroCodez
@BroCodez 7 ай бұрын
# 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 5 ай бұрын
Hi bro thank you for lessons I like your you tube channel
@rashidchibvuri2036
@rashidchibvuri2036 Ай бұрын
def __awesome_teacher(self, thank_u_sir)
@jankiwen3112
@jankiwen3112 6 ай бұрын
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.
@dendell8860
@dendell8860 Ай бұрын
Excellent..❤
@agyekumderrick9449
@agyekumderrick9449 7 ай бұрын
Bro to the world👊🏼, thanks for the updates all the time
@tejareddy6070
@tejareddy6070 Ай бұрын
thank you so much broo you are teaching in a way that everyone will understand
@shirinMN
@shirinMN 2 ай бұрын
you are so amazing i like the way you teach and your voice too💯
@uzairzarry8691
@uzairzarry8691 7 ай бұрын
Great explanation❤
@matchalover08
@matchalover08 6 ай бұрын
Just started a new semester on algorithms, this posted at the right time for my revision! Thx bro!
@Hussain.115
@Hussain.115 6 ай бұрын
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 5 ай бұрын
same here 😅
@oliya_b
@oliya_b 3 ай бұрын
Thank you for this clear explanation! You're such a good teacher! Thank you a lot😊
@zedzpan
@zedzpan 7 ай бұрын
Love how you made this so simple to understand. Dunder methods were always weird to me!
@sivaranjinidhilip850
@sivaranjinidhilip850 2 ай бұрын
Thank you.Very clear explanation
@AbdiDuale-m8w
@AbdiDuale-m8w 2 ай бұрын
U r genius
@nazihakh3517
@nazihakh3517 7 ай бұрын
you are awesome! thanks bro!
@KnownUnknown5232
@KnownUnknown5232 7 ай бұрын
Bro you deserve way more likes
@vigneshs6842
@vigneshs6842 2 ай бұрын
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
@ashwalker1
@ashwalker1 7 ай бұрын
Thank you Bro Can't wait for video on gaming channel
@HhaytchJjay
@HhaytchJjay Ай бұрын
Do we have a specific explanation for what the "self.title = title" syntax is doing?
@nasiriqbal5475
@nasiriqbal5475 7 ай бұрын
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.
@kapibara2440
@kapibara2440 6 ай бұрын
Great video, thank you🎉🎉🎉
@MFaiqVaince
@MFaiqVaince 7 ай бұрын
Can you plz update your c# playlist with more stuff after this, it will be very handy
@cbbcbb6803
@cbbcbb6803 5 ай бұрын
I really like your tutorials. But, I hate having to contort my fingers in order to key in special chaeacters!
@patrickjohnsanchez9427
@patrickjohnsanchez9427 7 ай бұрын
Bro Next video series please node js thanks bro
@PriyanshModanwal
@PriyanshModanwal 7 ай бұрын
when will u drop the course ?
@MarianoBustos-i1f
@MarianoBustos-i1f 7 ай бұрын
Thanks Bro
@JAYY1631
@JAYY1631 7 ай бұрын
he's awesome bro
@botpad4921
@botpad4921 7 ай бұрын
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😎😎
@FromTheWombTotheGrave
@FromTheWombTotheGrave 7 ай бұрын
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
@robert-qn8hy
@robert-qn8hy 7 ай бұрын
can you please make a video on python generators and asynchorous programming please
@vitavita5509
@vitavita5509 7 ай бұрын
bro thx
@Zebrazebrazebrazebray
@Zebrazebrazebrazebray 7 ай бұрын
L e g e n d
@Maedot_tube3
@Maedot_tube3 7 ай бұрын
Pls bro code❤❤❤😊
@rawa97775
@rawa97775 7 ай бұрын
Bro please a tutorial about discord python. Please bro code
@samisalama3033
@samisalama3033 7 ай бұрын
Make a second 12 hour Python course.
5 Useful Dunder Methods In Python
16:10
Indently
Рет қаралды 68 М.
Let's code a beginner Python BANKING PROGRAM 💰
15:01
Bro Code
Рет қаралды 352 М.
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
God-Tier Developer Roadmap
16:42
Fireship
Рет қаралды 7 МЛН
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,8 МЛН
5 Tips To Write Better Python Functions
15:59
Indently
Рет қаралды 117 М.
Learn Python Object Oriented Programming! 🚗
12:18
Bro Code
Рет қаралды 39 М.
Learn Python @property in 7 minutes! ⚙️
7:43
Bro Code
Рет қаралды 10 М.
AsyncIO, await, and async - Concurrency in Python
9:12
Socratica
Рет қаралды 121 М.
Learn to code with an unfair advantage.
15:05
Jason Goodison
Рет қаралды 177 М.
Please Master This MAGIC Python Feature... 🪄
25:10
Tech With Tim
Рет қаралды 173 М.
Python OOP Tutorial 4: Inheritance - Creating Subclasses
19:40
Corey Schafer
Рет қаралды 1,4 МЛН
How I Would Learn Python FAST (if I could start over)
12:19
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН