python - classes objects

Pubblicato il: 12 gennaio 2024
sul canale di: 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


In questa pagina del sito puoi guardare il video online python - classes objects della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Learnbatta 12 gennaio 2024, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 168 volte e gli è piaciuto 10 spettatori. Buona visione!