{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Matematikai Algoritmusok és Felfedezések I.\n", "\n", "## 1. Előadás, Bevezetés a programozásba és a Python nyelvbe.\n", "\n", "### 2022 február 10." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## Technikai információk" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "### Oktatók\n", "Előadás: Damásdi Gábor \n", " - (Iroda: Déli 3.508)\n", " - Fogadó óra: Előzetes egyeztetés szerint. \n", "\n", "Gyakorlat: \n", " - Juhász Balázs juhaszb23@gmail.com \n", " - Dobrovoczki Péter pdobrovoczki@caesar.elte.hu\n", " - Rácz Dániel danielracz10@gmail.com" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### Anyagok elérhetősége:\n", "- [damasdigabor.web.elte.hu/teaching](https://damasdigabor.web.elte.hu/teaching)\n", "- [Kooplex](https://k8plex-edu.elte.hu/hub/)\n", "- [Youtube csatorna](https://www.youtube.com/playlist?list=PL3L6lTzsxoUTQkXTkzQnnPTNOcpvAthiw)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## Tantárgy célja\n", "\n", "- **Matematikusok számára hasznos programozási tudás átadása**\n", "- Programozás általános folyamatának gyakorlása\n", "- Egy programozási nyelv (Python) alapjainak elsajátítása\n", "- Matematikusoknak hasznos programozási könyvtárak megismerése\n", "- Matematikai algoritmusok implementálása\n", "\n", "- Alapozás későbbi órákhoz(Matematikai algoritmusok és felfedezések II, Algoritmusok tervezése és elemzése, Adatbányászat, Deep learning)\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### Tematika\n", "Három fő témakör lesz:\n", " - Programozás és Python alapjai\n", " - Hasznos könyvtárak\n", " - Matematikai algoritmusok" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### Tananyag\n", "Az előadás anyaga mindig elérhető lesz a honlapon. [damasdigabor.web.elte.hu/teaching](https://damasdigabor.web.elte.hu/teaching)\n", "#### Források\n", "- [Ács Judit anyaga](https://github.com/bmeaut/python_nlp_2018_spring)\n", "- [SciPy tananyag](https://scipy-lectures.org/index.html)\n", "- [A Python nyelv hivatalos honlapja](https://www.python.org/)\n", "- Sok egyéb\n", "\n", "#### Tutorialok\n", " - [Runestone Academy](https://runestone.academy/runestone/books/published/thinkcspy/index.html)\n", " - [RealPython](https://realpython.com/)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### Követelmények\n", "- A gyakorlat elvégzése\n", "- Két beadandó feladat elkészítése \n", "- A második beadandó feladat bemutatása (viszgaidőszakban)\n", "- Mindkét beadandó osztályozva lesz 1-től 5-ig. \n", "- A végső jegy, A és B osztályzat esetén: " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "source": [ "def vegsojegy(a,b):\n", " if a==1 or b==1:\n", " return 1\n", " if (a+b)%2==0:\n", " return (a+b)/2\n", " else:\n", " if b>a:\n", " return (a+b+1)/2\n", " else:\n", " return (a+b-1)/2" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Tehát a két jegy átlaga, és ha az nem egész, akkor a második beadandó jegye dönt. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Kérdések?" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Az általunk használt programozási környezet\n", "\n", "### A programozás sokszínűsége\n", "- Python\n", "- Jupyter\n", "- Kooplex\n", "- Anaconda" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## Jupyter\n", "\n", "\n", "- Jupyter - Egy web applikáció melyben olyan dokumentumokat hozhatunk létre, melyek élő kódot, képleteket, grafikonokat tartalmaznak. \n", "- A Jupyter fájlok kiterjesztése `.ipynb`\n", "- de konvertálható sok féle formátumba (HTML, PDF, LateX ...)\n", "- A tartalom cellákba van rendezve. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### Cella típusok\n", "\n", "\n", "1. kód cella (Python/R/Lua/... kód) \n", "2. szöveg cella\n", "3. markdown cella: Markdown által formatált szöveg" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "### Kód cella" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello world!\n" ] } ], "source": [ "print(\"Hello world!\") " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Az utolsó parancs visszatérési értéke kiíródik. (Általában)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/plain": [ "6" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 + 3\n", "1 + 4\n", "3 * 2" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Ez akár egy több értékből álló \"tuple\" is lehet. (Ahogy sok mindenre, a \"tuple\" szóra sem találtam jó fordítást. Talán \"többes\"?) " ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "süsü\n" ] }, { "data": { "text/plain": [ "(5, 7, 'hello world')" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "print(\"süsü\") \n", "2 + 3, 3 + 4, \"hello \" + \"world\" " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "#### Markdown cella\n", "\n", "**Ez itt félkövér**\n", "\n", "*Ez meg dőlt*\n", "\n", "| Ez | meg itt |\n", "| --- | --- |\n", "| egy | táblázat |\n", "| egy | táblázat |\n", "\n", "Még a Latex is működik:\n", "\n", "$$\n", " \\frac{1}{n}\\sin x= \\frac{sinx}{n}= \\frac{sixn}{n}= six\\frac{n}{n}=six=6\n", "$$\n", "\n" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "Ez meg csak egy unalmas szöveges cella" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "\n", "# Jupyter használata\n", "\n", "## Parancs mód és szerkesztési mód\n", "\n", "1. Parancs mód: utasítások végrehajtása a cellákon, a tartalmuk megváltoztatása nélkül. \n", " - A kijelölt cellák kékek\n", "2. Szerkesztési mód: Egy adott cella tartalmának módosítása. \n", " - A kijelölt cella zöld színű" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "### Váltás a módok között\n", "\n", "1. Esc: Szerkesztési -> Parancs\n", "2. Enter vagy dupla klikk: Parancs -> Szerkesztési" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## Cella futtatása szerkesztési módban\n", "\n", "1. Ctrl + Enter: cella futtatása\n", "2. Shift + Enter: cella futtatása és ugrás a következőre\n", "3. Alt + Enter: cella futtatása és új cella beszúrása" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Hasznos shortcutok parancs módban\n", "- enter: cella szerkesztése\n", "- a/b : cella beszúrása a kijelölt cella alá/fölé (az above/below alapján)\n", "- m/y : cella típusának váltása: Markdown/Kód\n", "- dd : cella törlése" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "# Cella mágia (cell magic)\n", "\n", "Speciális parancsok, amik módosítják a cella működését." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Wall time: 27.9 ms\n" ] } ], "source": [ "%%time\n", "\n", "for x in range(1000000):\n", " pass" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "10.3 ns ± 0.147 ns per loop (mean ± std. dev. of 7 runs, 100000000 loops each)\n" ] } ], "source": [ "%%timeit\n", "\n", "x = 2" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing hello.py\n" ] } ], "source": [ "%%writefile hello.py\n", "\n", "print(\"Hello world xyxcxy\")" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello world xyxcxy\n" ] } ], "source": [ "!python hello.py " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Az elérhető mágiák listája:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "application/json": { "cell": { "!": "OSMagics", "HTML": "Other", "SVG": "Other", "bash": "Other", "capture": "ExecutionMagics", "cmd": "Other", "debug": "ExecutionMagics", "file": "Other", "html": "DisplayMagics", "javascript": "DisplayMagics", "js": "DisplayMagics", "latex": "DisplayMagics", "markdown": "DisplayMagics", "perl": "Other", "prun": "ExecutionMagics", "pypy": "Other", "python": "Other", "python2": "Other", "python3": "Other", "ruby": "Other", "script": "ScriptMagics", "sh": "Other", "svg": "DisplayMagics", "sx": "OSMagics", "system": "OSMagics", "time": "ExecutionMagics", "timeit": "ExecutionMagics", "writefile": "OSMagics" }, "line": { "alias": "OSMagics", "alias_magic": "BasicMagics", "autoawait": "AsyncMagics", "autocall": "AutoMagics", "automagic": "AutoMagics", "autosave": "KernelMagics", "bookmark": "OSMagics", "cd": "OSMagics", "clear": "KernelMagics", "cls": "KernelMagics", "colors": "BasicMagics", "conda": "PackagingMagics", "config": "ConfigMagics", "connect_info": "KernelMagics", "copy": "Other", "ddir": "Other", "debug": "ExecutionMagics", "dhist": "OSMagics", "dirs": "OSMagics", "doctest_mode": "BasicMagics", "echo": "Other", "ed": "Other", "edit": "KernelMagics", "env": "OSMagics", "gui": "BasicMagics", "hist": "Other", "history": "HistoryMagics", "killbgscripts": "ScriptMagics", "ldir": "Other", "less": "KernelMagics", "load": "CodeMagics", "load_ext": "ExtensionMagics", "loadpy": "CodeMagics", "logoff": "LoggingMagics", "logon": "LoggingMagics", "logstart": "LoggingMagics", "logstate": "LoggingMagics", "logstop": "LoggingMagics", "ls": "Other", "lsmagic": "BasicMagics", "macro": "ExecutionMagics", "magic": "BasicMagics", "matplotlib": "PylabMagics", "mkdir": "Other", "more": "KernelMagics", "notebook": "BasicMagics", "page": "BasicMagics", "pastebin": "CodeMagics", "pdb": "ExecutionMagics", "pdef": "NamespaceMagics", "pdoc": "NamespaceMagics", "pfile": "NamespaceMagics", "pinfo": "NamespaceMagics", "pinfo2": "NamespaceMagics", "pip": "PackagingMagics", "popd": "OSMagics", "pprint": "BasicMagics", "precision": "BasicMagics", "prun": "ExecutionMagics", "psearch": "NamespaceMagics", "psource": "NamespaceMagics", "pushd": "OSMagics", "pwd": "OSMagics", "pycat": "OSMagics", "pylab": "PylabMagics", "qtconsole": "KernelMagics", "quickref": "BasicMagics", "recall": "HistoryMagics", "rehashx": "OSMagics", "reload_ext": "ExtensionMagics", "ren": "Other", "rep": "Other", "rerun": "HistoryMagics", "reset": "NamespaceMagics", "reset_selective": "NamespaceMagics", "rmdir": "Other", "run": "ExecutionMagics", "save": "CodeMagics", "sc": "OSMagics", "set_env": "OSMagics", "store": "StoreMagics", "sx": "OSMagics", "system": "OSMagics", "tb": "ExecutionMagics", "time": "ExecutionMagics", "timeit": "ExecutionMagics", "unalias": "OSMagics", "unload_ext": "ExtensionMagics", "who": "NamespaceMagics", "who_ls": "NamespaceMagics", "whos": "NamespaceMagics", "xdel": "NamespaceMagics", "xmode": "BasicMagics" } }, "text/plain": [ "Available line magics:\n", "%alias %alias_magic %autoawait %autocall %automagic %autosave %bookmark %cd %clear %cls %colors %conda %config %connect_info %copy %ddir %debug %dhist %dirs %doctest_mode %echo %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %macro %magic %matplotlib %mkdir %more %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %pip %popd %pprint %precision %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %ren %rep %rerun %reset %reset_selective %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode\n", "\n", "Available cell magics:\n", "%%! %%HTML %%SVG %%bash %%capture %%cmd %%debug %%file %%html %%javascript %%js %%latex %%markdown %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile\n", "\n", "Automagic is ON, % prefix IS NOT needed for line magics." ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%lsmagic" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Welcome to Python 3.7's help utility!\n", "\n", "If this is your first time using Python, you should definitely check out\n", "the tutorial on the Internet at https://docs.python.org/3.7/tutorial/.\n", "\n", "Enter the name of any module, keyword, or topic to get help on writing\n", "Python programs and using Python modules. To quit this help utility and\n", "return to the interpreter, just type \"quit\".\n", "\n", "To get a list of available modules, keywords, symbols, or topics, type\n", "\"modules\", \"keywords\", \"symbols\", or \"topics\". Each module also comes\n", "with a one-line summary of what it does; to list the modules whose name\n", "or summary contain a given string such as \"spam\", type \"modules spam\".\n", "\n", "help> exit\n", "No Python documentation found for 'exit'.\n", "Use help() to get the interactive help utility.\n", "Use help(str) for help on the str class.\n", "\n", "help> exit()\n", "No Python documentation found for 'exit()'.\n", "Use help() to get the interactive help utility.\n", "Use help(str) for help on the str class.\n", "\n", "help> quit\n", "\n", "You are now leaving help and returning to the Python interpreter.\n", "If you want to ask for help on a particular object directly from the\n", "interpreter, you can type \"help(object)\". Executing \"help('string')\"\n", "has the same effect as typing a particular string at the help> prompt.\n" ] } ], "source": [ "help()\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Mi történik a háttérben\n", "\n", "- minden notebook rendelkezik egy saját _Kernel_ -el (Python interpreter)\n", " - a kernel megszakítható vagy újraindítható a menüből (interrupt/restart) \n", " - **mindig** futtasd a `Kernel -> Restart & Run All` parancsot mielőtt beadnád a házifeladatot/beadandót, hogy megbizonyosodj róla, hogy minden rendben működik\n", "- minden cella egy közös namespace-ben él \n", "- a cellák tetszőleges sorrendben futtathatóak \n", "- ha újra megnyitunk egy notebookot akkor alapvetően az inputok és az outputok maradnak meg. Az objektumok nem!" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Ez fut először asd\n" ] } ], "source": [ "print(\"Ez fut először asd\")" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Aztán meg ez. Figyeld a számot bal oldalt.\n" ] } ], "source": [ "print(\"Aztán meg ez. Figyeld a számot bal oldalt.\")" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "a=3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`a` mutasson a 2 értékre." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a+a" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`a` még mindig a 2-re mutat" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "skip" } }, "source": [ "## A cellák ki és bemenete később is elérhető. " ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [ { "data": { "text/plain": [ "42" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "42" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [ { "data": { "text/plain": [ "42" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "skip" } }, "source": [ "Utolsó előtti output:" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [ { "data": { "text/plain": [ "'first'" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"first\"" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [ { "data": { "text/plain": [ "'second'" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"second\"" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [ { "data": { "text/plain": [ "'first'" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "__" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [ { "data": { "text/plain": [ "'second'" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "__" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "skip" } }, "source": [ "Utolsó előtti előtti:" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [ { "data": { "text/plain": [ "'second'" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "___" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "skip" } }, "source": [ "Az n. output is elérhető a `_output_count` változón keresztül. Ez csak akkor definiált ha az n. cellának volt kimenete.\n", "\n", "Itt egy módszer az összes elérhető output listázására. (A kódot majd később megérted)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [ { "data": { "text/plain": [ "['_3', '_4', '_9', '_14', '_15', '_16', '_17', '_18', '_19', '_20', '_21']" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(filter(lambda x: x.startswith('_') and \n", " x[1:].isdigit(), globals()))" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "skip" } }, "source": [ "## A bemenet hasonlóan elérhető\n", "\n", "Előző input:" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [ { "data": { "text/plain": [ "\"list(filter(lambda x: x.startswith('_') and \\n x[1:].isdigit(), globals()))\"" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_i" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "skip" } }, "source": [ "N. input:" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "slideshow": { "slide_type": "skip" } }, "outputs": [ { "data": { "text/plain": [ "'print(\"Hello world!\") '" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_i2" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Kooplex\n", "\n", "- https://k8plex-edu.elte.hu/hub/\n", "- Szerveren fut\n", "- Házifeladatok beadása\n", "- Beadandók beadás\n", "\n", "# Anaconda\n", "- saját gépeden fut\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# A Python programozási nyelv" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## A Python története\n", "\n", "\n", "- A Python egy holland programozó hobbi projektjeként indult. (Guido van Rossum)\n", "- Python 1.0 1994\n", "- Python 2.0 2000\n", " - garbage collector\n", " - Unicode támogatás\n", "- Python 3.0 2008\n", " - nem kompatibilis a korábbi verziókkal!! \n", "- Python2 End-of-Life (EOL): January 1, 2020 \n", " - Ezért mi is csak a 3-al foglalkozunk\n", " - Frissítsétek a SAGE-t!" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true, "slideshow": { "slide_type": "subslide" } }, "source": [ "## Python közösség és fejlesztés\n", "\n", "- Python Software Foundation nonprofit szervezet (Delaware, US)\n", "- egy erős közösség alakult ki, akik aktívan részt vesznek a fejlesztésben\n", "- nagy standard library\n", "- nagyon nagy third-party modul rendszer: PyPI (Python Package Index)\n", "- pip installer (pip = pip installs packages)\n", "\n" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "ename": "ModuleNotFoundError", "evalue": "No module named 'wikipedia'", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mwikipedia\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'wikipedia'" ] } ], "source": [ "import wikipedia" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wikipedia.search('Budapest')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [], "source": [ " import antigravity " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## Python felhasználása\n", " - Web és Internet \n", " - Tudományos számítások (Kifejezetten: Deep learning, Machine learning)\n", " - Tanítás" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# A Python általános tulajdonságai" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "### Interpretált és fordított (compiled) nyelvek. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\"Drawing\"\n", "\"Drawing\"\n" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\users\\user\\anaconda3\\envs\\clean2021\\lib\\site-packages\\IPython\\core\\display.py:717: UserWarning: Consider using IPython.display.IFrame instead\n", " warnings.warn(\"Consider using IPython.display.IFrame instead\")\n" ] }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.display import HTML\n", "HTML('')" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Valójában sok nyelv használ vegyes stratégiát, így a python is. Mi főleg interpretált nyelvként fogjuk használni.\n", "###### Interpretált\n", " - gyors programírás\n", " - könnyű hibajavítás\n", " - általában lassabb\n", " - kód és program nincs szétválasztva" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## Whitespaces\n", "\n", "- zárójelek helyett indentáció van és befolyásolja a program futását \n", "- nincsenek pontosvesszők " ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "n páratlan\n", "alma\n", "citrom\n", "körte\n" ] } ], "source": [ "n = 11\n", "if n % 2 == 0:\n", " print(\"n páros\")\n", " print(\"n páros\")\n", " print(\"n páros\")\n", "else:\n", " print(\"n páratlan\")\n", " print('alma')\n", " if 2==0:\n", " pass\n", " else:\n", " print('citrom')\n", "print('körte')\n", " " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## Dinamikus típuskezelés \n", "\n", "- Típusellenőrzés futásidőben történik és nem fordítási időben." ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n" ] } ], "source": [ "n = 2\n", "print(type(n))\n", "\n", "n = 2.1 \n", "print(type(n))\n", "\n", "n = \"foo\"\n", "print(type(n))" ] } ], "metadata": { "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.9" } }, "nbformat": 4, "nbformat_minor": 2 }