término ![]() |
definición ![]() |
|||
---|---|---|---|---|
python naming conv
|
function variables: snake-case class: CamelCase MY_CONSTANT, module my_module, package mypackage(dont use _)
|
|||
metaprogramming
|
potential for a program to have knowledge of or manipulate itself
|
|||
language primitive
|
you work on it with assembler, it is smallest "unit of processing" available high level languages as python dont use them, python suffers abstraction penalty which is penalty for having various features
|
|||
object vs instance
|
instance is an object that is built from class object is an instance of class
|
|||
instance attributes vs class attributes
|
instance are different in instances and class attributes have the same value in every instance
|
|||
inheritance
|
mechanizm dzielenia funkcjonalnosci miedzy klasami it is a process where one class take attributes and methods of another class
|
|||
isinstance()
|
built-in function isinstance(instance, Class) returns true if instance is instance of Class. it also would return true if Class would be parent Class(inherited)
|
|||
subclass vs superclass
|
subclass (child) the class that inherits from another class superclass (parent) the class being inherited from
|
|||
super()
|
returns temporary object of the superclass allowing calling its methods user in inheritance
|
|||
_var __var
|
its a mechanism, naming convetion _var tells programmer that this variable shouldnt be user outside of the class but you can access; object. _var(its just naming convention) EVERYTHING IN PYTHON IS PUBLIC __var(mechanism of hiding attribute) in class you just use attribute with __var but outside of class its name is changed(hidden) you can still access attribute but its name is: _MyClassName__var
|
|||
property
|
in object oriented languages is a special sort of class member, in functionality between field(attribute) and methods. In python property is class but is called a function @propery def length(self): return self. _length. @length. setter def length(self, length): self. _length=length
|
|||
Class, type
|
If we define class: Class Foo: pass, then it is actually an object created by an object type: type('Foo', (), {}) it is the same type is a class of a class
|
|||
metaclass
|
metaclass is above the class that is created, any class that is created is an instance of the "type" metaclass Class Foo(metaclass=type) nic nie zmiena bo metaclass kazdej klasy jest domyslnie type, type jest klasa dla klasy a slowo Class to zwykly syntax xd
|
|||
mutable types as class attribute
|
Class Foo: x=[] mutable data types: list, dict, set, class instances Jesli damy x. append(1) to dodamy 1 we wszystkich instancjach klasy Foo xD
|
|||
python scope
|
LEGB rule: local(function) scope, enclosing(nonlocal) scope, global(or module) scope, built-in scope
|
|||
python attributes
|
are evaluated on declaration(or import)
|
|||
asgi, wsgi
|
asynchronous server gateway interface(or web) asgi is successor, it is better
|
|||
assert vs raise
|
assert do debugowania, raise rzuca exception, assert mozna wylaczyc flaga -o if x==0: raise Exception("xD") assert x!=0, "Cannot divide by 0"
|
|||
exceptions
|
raise - throws exception at any time; assert - checks if certain condition is met, throws exception if it is not(by default AssertionError but can be changed) else - do smth if no exceptions encountered in try;. finally - do smth (doesnt matter if exception happened or not) try - all statements executed until exception encountered;. except - catch and handle exception(ex. Except AssertionError:) bad idea to except without any error(Except:)
|
|||
deep copy shallow copy
|
deep - makes fully independent object immutable data types doesnt really have difference between deep and shallow
|