python - classes objects

Опубликовано: 12 Январь 2024
на канале: 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


На этой странице сайта вы можете посмотреть видео онлайн python - classes objects длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Learnbatta 12 Январь 2024, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 168 раз и оно понравилось 10 зрителям. Приятного просмотра!