Created
April 1, 2015 11:16
-
-
Save dekoza/40c2ea1fefc625b19ec2 to your computer and use it in GitHub Desktop.
MSI: (Kurs Pythona) plik z przykładami z zajęć z dnia 1.04.2015
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: utf-8 | |
class Nazwa: | |
atrybut = "wartość" | |
def __init__(self, *args, **kwargs): # konstruktor | |
kod | |
def metoda(self): # self - wskaźnik na instancję, z której wywoływana jest metoda | |
print "Jestem metodą instancji %s" % self | |
@classmethod | |
def met_klasy(cls): # cls - wskaźnik do klasy, z której wywoływana jest metoda | |
print "Jestem metodą klasy %s" % cls | |
@staticmethod | |
def met_statyczna(): | |
print "Jestem metodą statyczną" | |
def funkcja(param1, opcja1=0, opcja2=5, *args, **kwargs): | |
print param1, opcja1, opcja2, args, kwargs | |
class A(object): | |
def hej(self): | |
print "hej" | |
class B(object): | |
def halo(self): | |
print "halo" | |
def hej(self): | |
print "HEJ" | |
class C(A, B): | |
def hej(self): | |
super(C, self).hej() | |
print "hej hej :)" | |
@property | |
def wiek(self): | |
return 42 | |
############################################### | |
# dekoratory | |
def paczka(f): | |
def funkcja(*args, **kwargs): | |
f(*args, **kwargs) | |
print "Komunikat: %s, %s" % (args, kwargs) | |
return funkcja | |
@paczka | |
def silnia(n): | |
print "Nie mam siły" | |
def operacja(lista=None): | |
if lista is None: | |
lista = [] | |
lista.append(1) | |
print lista | |
if __name__ == "__main__": | |
print "BLABALBALBALB" | |
print __name__ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment