Submit Search
Upload
สรุปงานผู้ทดสอบ
•
Download as DOCX, PDF
•
0 likes
•
111 views
Kittawan Pex Tampasert
Follow
Report
Share
Report
Share
1 of 2
Download now
Recommended
Korištenje dekoratora je jednostavno, no pisanje zna biti kompleksno. • Kroz jednostavne korake ćemo proći i naučiti dekoratore 1. Funkcije Kreiranje def, parametri, vraćanje vrijednosti, poziv funkcije def foo(): return 1 print foo() 1 2. Scope Namespace funkcije za identificiranje varijabli u tijelu funkcije a_string = "This is a global variable" def foo(): print a_string # 1 foo() This is a global variable 3. variable resolution rules Pristup globalnim varijablama (promjenjiv tip podataka podržava promjene) a = ["Pero"] b = "Pero” def foo(): a[0] = "Ivo” b = "Ivo" print locals() foo() print globals() print a 4. Variable lifetime Namespace je svaki puta kreiran i uništen prilikom poziva funkcije, ne postoji sintaksa za vrijednost varijable. def foo(): x = 1 foo() 5. Function arguments and parameters Parametri funkcije mogu biti nazivi ili pozicije def foo(x, y=0): return x - y print foo(3,1) print foo(3) 6. Nested function Python gleda scope outer prvo i pronalazi lokalnu varijablu kroz inner def outer(): x = 1 def inner(): print x inner() outer() 7. Functions are first class objects in Python Funkcije su objekti u Pythonu, (klase su također objekti), shvaćamo ih kao vrijednosti, te ih možemo koristiti npr. kao argumente. print issubclass(int, object) def foo(): pass print foo.__class__ print issubclass(foo.__class__, object) 8. Closures Inner funkcija definirana u ne globalnom scope pamti izgled namespace. def outer(): x = 1 def inner(): print x return inner foo = outer() foo() 9. Decorators def outer(some_func): def inner(): print "Before some_func" ret = some_func() print some_func.__name__ return ret + 1 return inner def foo(): return 1 decorated = outer(foo) print decorated() 10. Symbol @ applies a decorator def outer(some_func): def inner(): print "Before some_func" ret = some_func() print some_func.__name__ return ret + 1 return inner @outer def foo(): return 1 print foo() 11. *args and **kwargs def logger(func): def inner(*args, **kwargs): print "Argumenti su bili : %s, %s" %(args, kwargs) return func(*args, **kwargs) return inner @logger def fool(x,y=1): return x * y @logger def fool2(): return 2 print fool(5,2) print fool2() 12. functools.wraps from functools import wraps def logged(func): @wraps(func) def with_logging(*args, **kwargs): print func.__name__ + " was called" return func(*args, **kwargs) return with_logging @logged def f(x): """does some math""" return x + x * x print f(3) print f.__name__
Understanding Python decorators
Understanding Python decorators
JosipKatalinic
Program 1
Program 1
minesurat
6. Шаблоны
6.1 Шаблоны классов
6.1 Шаблоны классов
DEVTYPE
Java
Java
Dany Ianko
Brief
Brief
rachaelarcher123
Peribahasa
Peribahasa
Jenny 美
testing the upload
Test-abcd
Test-abcd
danilevi78
Ufc update oct2012
Ufc update oct2012
jprice2
Recommended
Korištenje dekoratora je jednostavno, no pisanje zna biti kompleksno. • Kroz jednostavne korake ćemo proći i naučiti dekoratore 1. Funkcije Kreiranje def, parametri, vraćanje vrijednosti, poziv funkcije def foo(): return 1 print foo() 1 2. Scope Namespace funkcije za identificiranje varijabli u tijelu funkcije a_string = "This is a global variable" def foo(): print a_string # 1 foo() This is a global variable 3. variable resolution rules Pristup globalnim varijablama (promjenjiv tip podataka podržava promjene) a = ["Pero"] b = "Pero” def foo(): a[0] = "Ivo” b = "Ivo" print locals() foo() print globals() print a 4. Variable lifetime Namespace je svaki puta kreiran i uništen prilikom poziva funkcije, ne postoji sintaksa za vrijednost varijable. def foo(): x = 1 foo() 5. Function arguments and parameters Parametri funkcije mogu biti nazivi ili pozicije def foo(x, y=0): return x - y print foo(3,1) print foo(3) 6. Nested function Python gleda scope outer prvo i pronalazi lokalnu varijablu kroz inner def outer(): x = 1 def inner(): print x inner() outer() 7. Functions are first class objects in Python Funkcije su objekti u Pythonu, (klase su također objekti), shvaćamo ih kao vrijednosti, te ih možemo koristiti npr. kao argumente. print issubclass(int, object) def foo(): pass print foo.__class__ print issubclass(foo.__class__, object) 8. Closures Inner funkcija definirana u ne globalnom scope pamti izgled namespace. def outer(): x = 1 def inner(): print x return inner foo = outer() foo() 9. Decorators def outer(some_func): def inner(): print "Before some_func" ret = some_func() print some_func.__name__ return ret + 1 return inner def foo(): return 1 decorated = outer(foo) print decorated() 10. Symbol @ applies a decorator def outer(some_func): def inner(): print "Before some_func" ret = some_func() print some_func.__name__ return ret + 1 return inner @outer def foo(): return 1 print foo() 11. *args and **kwargs def logger(func): def inner(*args, **kwargs): print "Argumenti su bili : %s, %s" %(args, kwargs) return func(*args, **kwargs) return inner @logger def fool(x,y=1): return x * y @logger def fool2(): return 2 print fool(5,2) print fool2() 12. functools.wraps from functools import wraps def logged(func): @wraps(func) def with_logging(*args, **kwargs): print func.__name__ + " was called" return func(*args, **kwargs) return with_logging @logged def f(x): """does some math""" return x + x * x print f(3) print f.__name__
Understanding Python decorators
Understanding Python decorators
JosipKatalinic
Program 1
Program 1
minesurat
6. Шаблоны
6.1 Шаблоны классов
6.1 Шаблоны классов
DEVTYPE
Java
Java
Dany Ianko
Brief
Brief
rachaelarcher123
Peribahasa
Peribahasa
Jenny 美
testing the upload
Test-abcd
Test-abcd
danilevi78
Ufc update oct2012
Ufc update oct2012
jprice2
Call sheet
Call sheet
alllllexx
Lorena
Lorena
lorenaylua
Aluno 2
Aluno 2
Escola Figueiredo Correia
Hot spieces and proteins benefit
Hotspieces
Hotspieces
teammattons
Menú octubre 2
Menú octubre 2
adrianoloras
Animation pédagogique Art Visuel
Description d'oeuvres
Description d'oeuvres
skergoet
The primary functions of our work is to assist shareholders in exercising their voting rights and minimize operational risk for companies by achieving the necessary quorum levels and reducing negative participation
ProxyCensus Factsheet
ProxyCensus Factsheet
ProxyCensus Ltd
Bachelor
Bachelor
Phillip Engidius
Dedicaçao
Dedicaçao
Atividades Diversas Cláudia
Artículo para el periódico escolar del colegio Teodoro Aya Villaveces de Fusagasugá, 2012
Articulo tecnologia
Articulo tecnologia
davidcito56
Education
علم الرمل
علم الرمل
almabsli
More Related Content
Viewers also liked
Call sheet
Call sheet
alllllexx
Lorena
Lorena
lorenaylua
Aluno 2
Aluno 2
Escola Figueiredo Correia
Hot spieces and proteins benefit
Hotspieces
Hotspieces
teammattons
Menú octubre 2
Menú octubre 2
adrianoloras
Animation pédagogique Art Visuel
Description d'oeuvres
Description d'oeuvres
skergoet
The primary functions of our work is to assist shareholders in exercising their voting rights and minimize operational risk for companies by achieving the necessary quorum levels and reducing negative participation
ProxyCensus Factsheet
ProxyCensus Factsheet
ProxyCensus Ltd
Bachelor
Bachelor
Phillip Engidius
Dedicaçao
Dedicaçao
Atividades Diversas Cláudia
Artículo para el periódico escolar del colegio Teodoro Aya Villaveces de Fusagasugá, 2012
Articulo tecnologia
Articulo tecnologia
davidcito56
Education
علم الرمل
علم الرمل
almabsli
Viewers also liked
(11)
Call sheet
Call sheet
Lorena
Lorena
Aluno 2
Aluno 2
Hotspieces
Hotspieces
Menú octubre 2
Menú octubre 2
Description d'oeuvres
Description d'oeuvres
ProxyCensus Factsheet
ProxyCensus Factsheet
Bachelor
Bachelor
Dedicaçao
Dedicaçao
Articulo tecnologia
Articulo tecnologia
علم الرمل
علم الرمل
สรุปงานผู้ทดสอบ
1.
1. 2. 3. 4. Powerpoint 5. 1. 2. Powerpoint 3. 4. 5. int function_name(type arg,…) void function_name(type arg,…) function_name(type arg,…) void function_name() (
2.
() {} []
Download now