class: center, middle # Python ### Podsumowanie 2/2 ### 07/06/2019 Paweł Suder
https://pasuder.github.io/labs/doc/lab06 --- # Agenda 1. Tematy 2. Materiały --- # Tematy Na dzisiaj: - python - dodatkowe materiały --- ## python - typy podstawowe: set i dict - instrukcje sterujące - funkcje: parametry, domknięcia i dekoratory - interpreter --- ## python - typy Typy wbudowane - wybrane przykłady: - [zbiory](https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset) - [słowniki](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict) --- ## python - typy ```python >>> i = {0, 1, 2} >>> type(i)
>>> i = {0:'0', 1:'1', 2:'2'} >>> type(i)
``` --- ## python Instrukcje [sterujące](https://docs.python.org/3/tutorial/controlflow.html): - warunkowe [`if`](https://docs.python.org/3/tutorial/controlflow.html#if-statements) - pętle [`while`](https://docs.python.org/3/tutorial/introduction.html#first-steps-towards-programming) i [`for`](https://docs.python.org/3/tutorial/controlflow.html#for-statements) - sterowanie w pętli przy pomocy [`break`, `continue` i `else`](https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops) - obsługi wyjątków przy pomocy [`try..except..else..finally`](https://docs.python.org/3/tutorial/errors.html#handling-exceptions) - kontekstu przy pomocy `with` --- ## python - instrukcje ```python >>> i = True >>> if i: ... print('OK') ... else: ... print('Bad') ... OK >>> i = 2 >>> if i < 1: ... print('Mniejsze niz 1') ... else: ... print('Wieksze lub rowne 1') ... Wieksze lub rowne 1 ``` --- ## python - instrukcje ```python >>> i = 1 >>> if i < 1: ... print('Mniejsze niz 1') ... elif i > 1: ... print('Wieksze niz 1') ... else: # elif i == 1 ... print('Rowne 1') ... Rowne 1 ``` --- ## python - instrukcje ```python >>> i = 1 >>> while i < 3: ... print(i) ... i = i + 1 ... print(i) 1 2 >>> print(i) 3 ``` --- ## python - instrukcje ```python >>> i = 1 >>> while i < 5: ... print(i) ... if i % 3 == 0: ... print('Koncz szybciej..') ... break ... i = i + 1 ... 1 2 3 Koncz szybciej.. >>> print(i) 3 ``` --- ## python - instrukcje ```python >>> i = 1 >>> while i < 21: ... print(i) ... if i % 2 == 1: ... print('Mnoze przez 3 i dodaje 1 do %d' % i) ... i = i * 3 + 1 ... continue ... print('Dodaje 1 do %d' % i) ... i = i + 1 ... 1 Mnoze przez 3 i dodaje 1 do 1 4 Dodaje 1 do 4 5 ... ``` --- ## python - instrukcje ```python >>> i = 3 >>> while i < 2: ... print(i) ... else: ... print('Nic nie zrobilem..') ... Nic nie zrobilem.. ``` --- ## python Odnośniki do slajdów (niektóre z tematów): - [wyjątki](https://pasuder.github.io/labs/doc/lab02/#3) - [blok `with`](https://pasuder.github.io/labs/doc/lab02/#6) - [domknięcia](https://pasuder.github.io/labs/doc/lab03/#3) i [dekoratory](https://pasuder.github.io/labs/doc/lab03/#5) Polecam zapoznać się z [tutorialem](https://docs.python.org/3/tutorial/index.html), aby uporządkować wiedzę 😃 --- ## python - cpython - podstawowa, referencyjna implementacja - activepython - anaconda - ironpython - jython - micropython - miniconda - pypy - pyston - stackless --- ## python ### cpython - The "traditional" implementation of Python (nicknamed CPython). - CPython is the default byte-code interpreter of Python, which is written in C. - [CPython](https://wiki.python.org/moin/CPython) is Guido van Rossum's reference version of the Python computing language. It's most often called simply "Python"; speakers say "CPython" generally to distinguish it explicitly from other implementations. - [Python vs CPython](https://stackoverflow.com/q/17130975) - It is a [Virtual stack machine](https://en.wikipedia.org/wiki/Stack_machine#Virtual_stack_machines). --- ## python ### pypy PyPy is a replacement for CPython. It is built using the RPython language that was co-developed with it. The main reason to use it instead of CPython is speed: it runs generally faster. PyPy implements Python 2.7.13 and 3.5.3. [Features](https://pypy.org/features.html): - speed - memory usage - stackless --- ## python ### stackless [..] named because it avoids depending on the C call stack for its own stack. [..] Stackless Python uses the C stack, but the stack is cleared between function calls. The most prominent feature of Stackless is microthreads, which avoid much of the overhead associated with usual operating system threads. [Source](https://en.wikipedia.org/wiki/Stackless_Python) [More](https://github.com/stackless-dev/stackless/wiki) --- ## python ### jython Jython: Python for the Java Platform. Jython 3.x development is in progress. Jython 2.7.0 was released on May 3, 2015. Jython 2.7.1 release candidates will be released soon (September 2015). [What is Jython?](https://wiki.python.org/jython/JythonFaq/GeneralInfo) [Why Jython?](https://wiki.python.org/jython/WhyJython) --- ## python ### ironpython IronPython is an excellent addition to the .NET Framework, providing Python developers with the power of the .NET framework. Existing .NET developers can also use IronPython as a fast and expressive scripting language for embedding, testing, or writing a new application from scratch. IronPython 2.7.8 is now available! (February 16, 2018) --- ## python - [activepython](https://www.activestate.com/products/activepython/) - [commercial version](https://wiki.python.org/moin/ActivePython) - [anaconda](https://www.anaconda.com/) - data science - [micropython](https://micropython.org/) - python3 for microcontrollers - [miniconda](https://docs.conda.io/en/latest/miniconda.html) - minimal version of anaconda, without extra packages, just repo mgmt stuff - [pyston](https://github.com/dropbox/pyston) - performance-oriented, LLVM, JIT --- ## python Do zarządzania wersjami python na Linux: [PyEnv](https://github.com/pyenv/pyenv). Dobre dla środowisk deweloperskich. Dla aplikacji produkcyjnych: lepiej korzystać z obrazów bazowych dla kontenerów, np.: Docker: - https://hub.docker.com/_/python - https://hub.docker.com/_/pypy [Przykład Dockerfile](https://github.com/suderdev/multi-editor/blob/master/Dockerfile) --- ## python - [(official) CPython internals](https://devguide.python.org/exploring/) - [Python internals in short](https://medium.com/@dawranliou/getting-started-with-python-internals-a5474ccb8022) - [Python stack machine explained](https://opensource.com/article/18/4/introduction-python-bytecode) - [CPython internals](http://www.pgbovine.net/cpython-internals.htm) - [Python interpreter in python](https://www.aosabook.org/en/500L/a-python-interpreter-written-in-python.html) - [Inside The Python Virtual Machine](https://leanpub.com/insidethepythonvirtualmachine/read) --- ## Inne materiały - Książka [Algorytmy + struktury danych = programy](http://lubimyczytac.pl/ksiazka/122213/algorytmy-struktury-danych-programy) - [Strona](http://www.algorytm.org/algorytmy/) z algorytmami i innymi rzeczami, które są (były) poruszane na WDI (Wstęp do Informatyki) - [Ważniak](http://wazniak.mimuw.edu.pl/) - [Wstęp do programowania](http://wazniak.mimuw.edu.pl/index.php?title=Wst%C4%99p_do_programowania) - [Algorytmy i struktury danych](http://wazniak.mimuw.edu.pl/index.php?title=Algorytmy_i_struktury_danych) --- class: center, middle
_Dziękuję!_