TDI: The Great Divide — 'def' vs 'class
While writing my lines (codes), I found out 2 similar keywords: def (define) and class (classification).
Many Python explorers like me will be very curious about their differences, so after some research, I found out that they have a lot of differences. Let's look at their roles when building a tool with Python.
( 1 ) def (Create a Function)
Effects: You "tell" the computer to do something.
Where to Use: When you need to calculate a specific equation, for example, like density calculation, 'def' can be the quickest way to calculate.
Disadvantage: It's like a microphone; you give it something, and it sends back the result, but it can't "remember" anything.
( 2 ) class (Classification / Blueprint)
Effects: You are creating a blueprint that has memory and power.
Where to Use: When you need to invent a system, this system needs to control a lot of things, like coordinates, color, or what time you should open this system.
Advantage: What is different from 'def' is that it can remember what's in its "mind", so you don't need to put in a parameter every time you start it.
Comparison Summary:
defis Action-oriented (Focusing on the process).classis Entity-oriented (Focusing on the object and its state).
As a Python explorer, I use def to perform specific tasks and class to build the structure of my application.
