python

 0    20 tarjetas    patrykdastych
imprimir jugar test de práctica
 
término - definición -
python naming conv
empezar lección
function variables: snake-case class: CamelCase
MY_CONSTANT, module my_module, package mypackage(dont use _)
metaprogramming
empezar lección
potential for a program to have knowledge of or manipulate itself
language primitive
empezar lección
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
empezar lección
instance is an object that is built from class
object is an instance of class
instance attributes vs class attributes
empezar lección
instance are different in instances and class attributes have the same value in every instance
inheritance
empezar lección
mechanizm dzielenia funkcjonalnosci miedzy klasami
it is a process where one class take attributes and methods of another class
isinstance()
empezar lección
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
empezar lección
subclass (child) the class that inherits from another class
superclass (parent) the class being inherited from
super()
empezar lección
returns temporary object of the superclass allowing calling its methods
user in inheritance
_var __var
empezar lección
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
empezar lección
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
empezar lección
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
empezar lección
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
empezar lección
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
empezar lección
LEGB rule: local(function) scope, enclosing(nonlocal) scope, global(or module) scope, built-in scope
python attributes
empezar lección
are evaluated on declaration(or import)
asgi, wsgi
empezar lección
asynchronous server gateway interface(or web)
asgi is successor, it is better
assert vs raise
empezar lección
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
empezar lección
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
empezar lección
deep - makes fully independent object
immutable data types doesnt really have difference between deep and shallow

Debes iniciar sesión para poder comentar.