python - classes objects

Опубликовано: 11 Май 2025
на канале: Learnbatta
168
10

what is a class?

Class is a template for an object
Class should follow camel case notation
All classes in one file - when classes are short
One class per file - when classes are long

when to use a class?

Several functions with share state
More than one copy of the same state variables
To extend the behavior of an existing functionality
Do not use classes for simple things

Example:

class Calculator:
pi = 3.14

def add(self, num1, num2):
return num1 + num2

def sub(self, num1, num2):
return num1 - num2

References
https://docs.python.org/dev/tutorial/...
https://learnbatta.com/course/python/...

#python #python3 #class #object #learning #learnbatta