{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Numbers" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1024\n" ] } ], "source": [ "# Potęgowanie...\n", "a = 2**10\n", "print(a)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/plain": [ "9223372036854775808" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2**63" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/plain": [ "340282366920938463463374607431768211456" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2**128" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "text/plain": [ "13182040934309431001038897942365913631840191610932727690928034502417569281128344551079752123172122033140940756480716823038446817694240581281731062452512184038544674444386888956328970642771993930036586552924249514488832183389415832375620009284922608946111038578754077913265440918583125586050431647284603636490823850007826811672468900210689104488089485347192152708820119765006125944858397761874669301278745233504796586994514054435217053803732703240283400815926169348364799472716094576894007243168662568886603065832486830606125017643356469732407252874567217733694824236675323341755681839221954693820456072020253884371226826844858636194212875139566587445390068014747975813971748114770439248826688667129237954128555841874460665729630492658600179338272579110020881228767361200603478973120168893997574353727653998969223092798255701666067972698906236921628764772837915526086464389161570534616956703744840502975279094087587298968423516531626090898389351449020056851221079048966718878943309232071978575639877208621237040940126912767610658141079378758043403611425454744180577150855204937163460902512732551260539639221457005977247266676344018155647509515396711351487546062479444592779055555421362722504575706910949376" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2**4000" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "data": { "text/plain": [ "1205" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = len(str(2**4000))\n", "a" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1.0 / 10 == 0.1" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "0.1 == 0.10000000000000001" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "# Data types" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Lists" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0, 1, 2, 3]\n" ] } ], "source": [ "arr = [0,1,2,3]\n", "print(arr)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[1, 2, 'cos', [10, 11, 12], 3.14]\n" ] } ], "source": [ "# Listy w pythonie są bardzo elastyczne\n", "arr = [1,2,'cos', [10,11,12], 3.14]\n", "print(arr)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0, 1, 2, 3]\n" ] } ], "source": [ "arr = [0,1,2,3]\n", "print(arr)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(arr)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Wartość której komórki zostanie odczytana?\n", "arr[1]" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Elementy listy można łatwo nadpisać\n", "arr[2] = 2\n", "arr[2]" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "arr[1] = 1" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Czy to zadziała?\n", "arr[-1]" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Wartości których komórek zostaną odczytane?\n", "arr[1:3]" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, 2]" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr[:3]" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[2, 3]" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr[-2:]" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2]" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr[-3:-1]" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, 2, 3, 4]" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr = [0,1,2,3,4,5,6]\n", "arr[0:5]" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 2, 4]" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr[0:5:2]" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 2, 4, 6]" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr[::2]" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[6, 5, 4, 3, 2, 1, 0]" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr[::-1]" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, 2, 3, 'a', 'b', 'c', 'd']" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Konkatenacja\n", "a=[0,1,2,3]\n", "b=['a','b','c','d']\n", "a+b" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[10, 20, 30, 40, 100]" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Dodawanie do listy\n", "a=[10,20,30,40]\n", "a.append(100)\n", "a" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[10, 20, 30]" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Usuwanie z listy\n", "a=[10,20,20,30,40]\n", "a.remove(20)\n", "a.pop(3)\n", "a" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Python ma wiele fajnych funkcji, np.\n", "a = [4, 6, 'd','y', 3 ,6]\n", "'d' in a" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.index('d')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Tuples" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1, 2, 3)" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Czym się różni tuple od listy? (Poza nawiasami)\n", "a = (1,2,3)\n", "a" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Czytamy tak samo\n", "a[0]" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1, 2, 3, 2, 3, 4)" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b = (2,3,4)\n", "\n", "c = a + b\n", "c" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(2, 3, 4, 1, 2, 3, 2, 3, 4)" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d = b + c\n", "d" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "ename": "TypeError", "evalue": "'tuple' object does not support item assignment", "output_type": "error", "traceback": [ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", "\u001B[0;31mTypeError\u001B[0m Traceback (most recent call last)", "\u001B[0;32m\u001B[0m in \u001B[0;36m\u001B[0;34m()\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[0;31m# Co się teraz stanie?\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m----> 2\u001B[0;31m \u001B[0ma\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;36m1\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;36m1\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m", "\u001B[0;31mTypeError\u001B[0m: 'tuple' object does not support item assignment" ] } ], "source": [ "# Co się teraz stanie?\n", "a[1]=1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Dictionaries" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'fizyka': 4, 'informatyka': 6, 'matematyka': 5, 'polski': 3.5}" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "oceny = {'polski': 3.5, \n", " 'matematyka': 5,\n", " 'fizyka': 4, \n", " 'informatyka': 6}\n", "oceny" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Odczytanie wartości dla klucza\n", "oceny['informatyka']" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "ename": "KeyError", "evalue": "'wf'", "output_type": "error", "traceback": [ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", "\u001B[0;31mKeyError\u001B[0m Traceback (most recent call last)", "\u001B[0;32m\u001B[0m in \u001B[0;36m\u001B[0;34m()\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[0;31m# A teraz?\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m----> 2\u001B[0;31m \u001B[0moceny\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;34m'wf'\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m", "\u001B[0;31mKeyError\u001B[0m: 'wf'" ] } ], "source": [ "# A teraz?\n", "oceny['wf']" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'fizyka': 4,\n", " 'informatyka': 6,\n", " 'matematyka': 5,\n", " 'nowy przedmiot': 2.0,\n", " 'polski': 3.5}" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Łatwo można dodać ocenę\n", "oceny['nowy przedmiot'] = 2.0\n", "oceny" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'fizyka': 4,\n", " 'informatyka': 6,\n", " 'matematyka': 5,\n", " 'nowy przedmiot': 4.0,\n", " 'polski': 3.5}" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# A także nadpisać \n", "oceny['nowy przedmiot'] = 4.0\n", "oceny" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Sets" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'geografia', 'historia', 'muzyka', 'polski'}" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Zbiory. Takie jak w matematyce. Jakie są dwie podstawowe włąsności zbiorów? \n", "ulubione_przedmioty = set(['polski', 'muzyka', 'geografia', 'historia'])\n", "ulubione_przedmioty" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Czy element należy do zbioru?\n", "'informatyka' in ulubione_przedmioty\n", "#'polski' in ulubione_przedmioty" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Kocham j. polski!\n" ] } ], "source": [ "# Zastosowanie z ifem (data flow będzie dalej)\n", "# UWAGA NA WCIĘCIA\n", "if 'polski' in ulubione_przedmioty:\n", " print('Kocham j. polski!')" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['a', 'd', 'f', 'b', 'c', 'e']\n" ] } ], "source": [ "a = set(['a','b','c','d'])\n", "b = set(['c','d','e','f'])\n", "a = a.union(b)\n", "l = list(a)\n", "print(l)" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'c', 'd', 'e', 'f'}" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.intersection(b)" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'a', 'b'}" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.difference(b)" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[1, 2, 'b', 4, 'c']\n" ] } ], "source": [ "# Jak usunąć duplikaty z listy?\n", "l = [1, 2, 'b', 4, 2, 'b', 'c']\n", "s = set(l)\n", "nl = list(s)\n", "print(nl)" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "ename": "AttributeError", "evalue": "'set' object has no attribute 'index'", "output_type": "error", "traceback": [ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", "\u001B[0;31mAttributeError\u001B[0m Traceback (most recent call last)", "\u001B[0;32m\u001B[0m in \u001B[0;36m\u001B[0;34m()\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[0;31m# Dlaczego nie można tak?\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 2\u001B[0m \u001B[0ms\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mset\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;34m'a'\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m'b'\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m'c'\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m----> 3\u001B[0;31m \u001B[0mpos\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0ms\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mindex\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m'a'\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m", "\u001B[0;31mAttributeError\u001B[0m: 'set' object has no attribute 'index'" ] } ], "source": [ "# Dlaczego nie można tak?\n", "s = set(['a', 'b', 'c'])\n", "pos = s.index('a')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Strings" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "asdasdas 4\n" ] } ], "source": [ "a = 4\n", "print('asdasdas ' + str(a))" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Imię: Wojciech\n" ] } ], "source": [ "# łańcuchy znaków...\n", "print('Imię: {}'.format('Wojciech'))" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Imię: Wojciech,\n", " Nazwisko: Jaśkowski,\n", " PESEL: 8212...,\n", " Ulubiona: 3.141592653589793\n", "\n" ] } ], "source": [ "from math import pi\n", "print(' Imię: {},\\n Nazwisko: {},\\n PESEL: {},\\n Ulubiona: {}\\n'\n", " .format('Wojciech', 'Jaśkowski', '8212...', pi))" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " \n", "Imię: Wojciech,\n", "Nazwisko: Jaśkowski,\n", "PESEL: 8212...,\n", "Ulubiona: 3.141592653589793\n", "\n" ] } ], "source": [ "# Można nadać identyfikator {identyfikator}\n", "# Czy kolejnośc ma w takim razie znaczenie?\n", "from math import pi\n", "print(''' \n", "Imię: {imie},\n", "Nazwisko: {nazw},\n", "PESEL: {pesel},\n", "Ulubiona: {ulub}\n", "'''.format(\n", " nazw='Jaśkowski', \n", " imie='Wojciech', \n", " pesel='8212...', \n", " ulub=pi))" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ęśćńżół\n", "יהוה\n" ] } ], "source": [ "# Czy da radę to wyświetlić?\n", "print('ęśćńżół')\n", "print('יהוה')" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "al\n" ] } ], "source": [ "# Po łańcuchu znaków można w sumie iterować, więc...\n", "s = 'ala'\n", "print(s[0:2])" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ala\n", "ala\n" ] } ], "source": [ "# Czy jest jakaś różnica?\n", "print('ala')\n", "print(\"ala\")" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ala ma ' \"kota\"\n", "ala ma 'kota'\n" ] } ], "source": [ "# Ciekawostka\n", "print('ala ma \\' \"kota\"')\n", "print(\"ala ma 'kota'\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "# Bardzo łatwo można w pythonie dokonywać konwersji między łańcuchem znaków a inną zmienną.\n", "str(12)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "int('12')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "float('12.1')" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Python', 'is', 'easy;really?']" ] }, "execution_count": 61, "metadata": {}, "output_type": "execute_result" } ], "source": [ "text = 'Python is easy;really?'\n", "text.split()" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Python is easy', 'really?']" ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "text.split(';')" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Python', 'is', 'easy', 'really?']" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Wciąż nie fajnie, ale...\n", "import re\n", "re.split(' |;', text)" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"['a', 'b', 'c', 'd']\"" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr = ['a','b','c','d']\n", "str(arr)" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'a; b; c; d'" ] }, "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'; '.join(arr)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Flow control" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a\n", "b\n", "c\n", "d\n" ] } ], "source": [ "arr = ['a', 'b', 'c', 'd']\n", "for a in arr: \n", " print(a)" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 1, 2, 3]" ] }, "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(range(0, 4))" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 a\n", "1 b\n", "2 c\n", "3 d\n" ] } ], "source": [ "for i in range(len(arr)):\n", " print(i, arr[i])" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 a\n", "1 b\n", "2 c\n", "3 d\n" ] } ], "source": [ "# W poprzednich podejściach mieliśmy albo element, albo indeks. \n", "# A można mieć to i to \n", "\n", "list(enumerate(arr))\n", "\n", "for i, a in enumerate(arr):\n", " print(i, a)" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 a\n", "1 b\n", "2 c\n", "3 d\n" ] } ], "source": [ "a = [0,1,2,3]\n", "b = ['a','b','c','d']\n", "n = len(a)\n", "for i in range(n):\n", " print(a[i], b[i])" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 a\n", "1 b\n", "2 c\n", "3 d\n" ] } ], "source": [ "# A co jeżeli chcemy iterować jednocześnie po dwóch listach?\n", "a = [0,1,2,3]\n", "b = ['a','b','c','d']\n", "for x, y in zip(a, b):\n", " print(x, y)" ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')]" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(zip(a,b))" ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(0, 'a', 'ala'), (1, 'b', 'ma'), (2, 'c', 'kota'), (3, 'd', '!')]" ] }, "execution_count": 75, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# A po trzech?\n", "c=['ala','ma','kota','!']\n", "zipped = list(zip(a,b,c))\n", "zipped" ] }, { "cell_type": "code", "execution_count": 76, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(0, 1, 2, 3)\n", "('a', 'b', 'c', 'd')\n", "('ala', 'ma', 'kota', '!')\n" ] } ], "source": [ "# Skoro można 'zipować', to można także 'odzipować'\n", "a, b, c = list(zip(*zipped))\n", "print(a)\n", "print(b)\n", "print(c)" ] }, { "cell_type": "code", "execution_count": 77, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 = 0 mod 3\n", "1 = 1 mod 3\n", "2 = 2 mod 3\n", "0 = 3 mod 3\n" ] } ], "source": [ "# If w pythonie jest bardzo prosty (pamiętamy o ':' oraz braku '{ }')\n", "arr = [0,1,2,3]\n", "for a in arr:\n", " if (a % 3 == 0):\n", " print('0 = {} mod 3'.format(a))\n", " elif a % 3 == 1:\n", " print('1 = {} mod 3'.format(a))\n", " else:\n", " print('2 = {} mod 3'.format(a))" ] }, { "cell_type": "code", "execution_count": 78, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hon\n" ] } ], "source": [ "# Pętla while to też pestka. Jaki tu będzie wynik?\n", "s = 'python'\n", "while s[0] != 'h':\n", " s = s[1:]\n", "print(s)" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A is in range\n" ] } ], "source": [ "# and (nawiasy nie są konieczne)\n", "a = 1\n", "if -1 <= a and (a <= 1):\n", " print('A is in range')" ] }, { "cell_type": "code", "execution_count": 81, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A is in range\n" ] } ], "source": [ "# 'and' czasami też nie jest konieczny...\n", "if -1 <= a <= 1:\n", " print('A is in range')" ] }, { "cell_type": "code", "execution_count": 82, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4 is missing\n" ] } ], "source": [ "# negacja \n", "a = [1, 2, 3]\n", "if not 4 in a:\n", " print('4 is missing')" ] }, { "cell_type": "code", "execution_count": 86, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3\n" ] } ], "source": [ "# continue, break\n", "a = 2\n", "while (a < 5):\n", " a = a + 1\n", " print(a)\n", " if (a == 3):\n", " break\n", " #continue" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Iterating over dictionaries" ] }, { "cell_type": "code", "execution_count": 87, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "12 => mama\n", "a => 1\n", "b => 2\n", "4 => 23\n" ] } ], "source": [ "# Co odczytujemy?\n", "# Co z kolejnością?\n", "\n", "d = {'a': 1, \n", " 'b': 2, \n", " 12: 'mama', \n", " 4:23}\n", "\n", "for v in d:\n", " print(str(v) + ' => ' + str(d[v]))" ] }, { "cell_type": "code", "execution_count": 88, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "12 => mama\n", "a => 1\n", "b => 2\n", "4 => 23\n" ] } ], "source": [ "# A gdybyśmy chcieli mieć klucz i wartość od razu?\n", "\n", "#list(d.items())\n", "\n", "for k, v in d.items():\n", " print(str(k) + ' => ' + str(v))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Functions" ] }, { "cell_type": "code", "execution_count": 89, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ok\n" ] } ], "source": [ "# Na początek proste dodawanie (pamiętamy o wcięciach, ':' oraz braku '{ }')\n", "\n", "def suma(a, b): \n", " return a + b\n", " \n", "if suma(1,3) == 4: print(\"ok\") # można w jednej linijce" ] }, { "cell_type": "code", "execution_count": 90, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Python wspiera wartości domyślne funkcji. Jaki będzie wynik?\n", "def suma(a, \n", " b, \n", " wa=1, \n", " wb=3):\n", " return wa * a + wb * b\n", "\n", "suma(1,1)" ] }, { "cell_type": "code", "execution_count": 94, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# A teraz?\n", "suma(1, 3, 2, 1)" ] }, { "cell_type": "code", "execution_count": 95, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "7" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Zamieniliśmy kolejność, odwołując się po identyfikatorach. Czy teraz się wyjdzie?\n", "suma(1, 3, wb=2, wa=1)" ] }, { "cell_type": "code", "execution_count": 96, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "11\n" ] } ], "source": [ "print(suma(1, 3, wa=2))" ] }, { "cell_type": "code", "execution_count": 97, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(1, 4)\n" ] } ], "source": [ "# Co ta funkcja robi?\n", "# Ile wartości ona zwraca?\n", "def f(arr):\n", " n = x = arr[0]\n", " for a in arr:\n", " if n > a:\n", " n = a\n", " if x < a:\n", " x = a\n", " return n, x\n", "\n", "print(f([2,3,1,4]))" ] }, { "cell_type": "code", "execution_count": 98, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(1, 4)\n", "1\n", "4\n" ] } ], "source": [ "# Jak to przechwycić?\n", "a = f([2,3,1,4])\n", "print(a)\n", "a, b = f([2,3,1,4])\n", "print(a)\n", "print(b)" ] }, { "cell_type": "code", "execution_count": 99, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "tuple" ] }, "execution_count": 99, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Czym jest x?\n", "x = f([2,3,1,4])\n", "type(x)" ] }, { "cell_type": "code", "execution_count": 100, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a = 2\n", "b = 1\n" ] } ], "source": [ "# Przkład operacji a, b = b, a (swap)\n", "a = 1\n", "b = 2\n", "a, b = b, a\n", "print('a = ' + str(a))\n", "print('b = ' + str(b))" ] }, { "cell_type": "code", "execution_count": 101, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a = ala\n", "b = ma\n", "c = kota\n" ] } ], "source": [ "# Taki inny unzip\n", "x = ('ala','ma','kota')\n", "a, b, c = x\n", "print('a = ' + str(a))\n", "print('b = ' + str(b))\n", "print('c = ' + str(c))" ] }, { "cell_type": "code", "execution_count": 102, "metadata": {}, "outputs": [ { "data": { "text/plain": [ ".g>" ] }, "execution_count": 102, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Pytanie za zero punktów. Co zwraca funkcja f?\n", "def f(wa=1, wb=1): \n", " def g(a, b):\n", " return a * wa + b * wb;\n", " return g\n", "\n", "f(1,3)" ] }, { "cell_type": "code", "execution_count": 103, "metadata": {}, "outputs": [ { "data": { "text/plain": [ ".g>" ] }, "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# W Javie czym musimy się posłużyć, żeby uzyskać taki efekt? \n", "wazona = f(0, 1)\n", "wazona" ] }, { "cell_type": "code", "execution_count": 104, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 104, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wazona(1, 3)" ] }, { "cell_type": "code", "execution_count": 105, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[-3, 1, 2, 4]" ] }, "execution_count": 105, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Gratisowa metoda listy. Wynik?\n", "arr = [-3, 2, 1, 4]\n", "arr.sort()\n", "arr" ] }, { "cell_type": "code", "execution_count": 106, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[4, 2, 1, -3]" ] }, "execution_count": 106, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# A teraz?\n", "arr.sort(reverse=True)\n", "arr" ] }, { "cell_type": "code", "execution_count": 107, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, -3, 4]" ] }, "execution_count": 107, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# A teraz?\n", "def mykey(x):\n", " return abs(x)\n", "arr.sort(key=mykey)\n", "arr" ] }, { "cell_type": "code", "execution_count": 108, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, -3, 4]" ] }, "execution_count": 108, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Możemy to zrobić 'inline' wykorzystując funkcje lambda.\n", "arr.sort(key=lambda x: abs(x))\n", "arr" ] }, { "cell_type": "code", "execution_count": 109, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-1\n" ] } ], "source": [ "# Utrwalmy funkcje lambda. Jaki będzie wynik?\n", "f = lambda a, b: a - b\n", "\n", "print(f(1,2))" ] }, { "cell_type": "code", "execution_count": 110, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3\n" ] } ], "source": [ "# A teraz?\n", "g = lambda a, b: a + b\n", "print(g(1,2))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "# A teraz? \n", "f, g = g, f\n", "print(f(1,2))\n", "print(g(1,2))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Various" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Complex numbers" ] }, { "cell_type": "code", "execution_count": 111, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1+3j)" ] }, "execution_count": 111, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Python obsługuje liczby zespolone\n", "1+3j" ] }, { "cell_type": "code", "execution_count": 112, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.1622776601683795" ] }, "execution_count": 112, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Czym jest moduł liczby zepolonej?\n", "abs(1+3j)" ] }, { "cell_type": "code", "execution_count": 113, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(5+5j)" ] }, "execution_count": 113, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(1+3j)*(2-1j)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generators (yield)" ] }, { "cell_type": "code", "execution_count": 114, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "# Normalnie, po wykonaniu funkcji, jej stan lokalny jest niszczony. Ale...\n", "# Co robi ten kod?\n", "\n", "def whatdoido():\n", " a, b = 0, 1\n", " while True:\n", " yield a\n", " a, b = b, a + b\n", "\n", "print(whatdoido())" ] }, { "cell_type": "code", "execution_count": 115, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n" ] } ], "source": [ "# Wynik?\n", "g = whatdoido()\n", "print(next(g))" ] }, { "cell_type": "code", "execution_count": 116, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n", "1\n", "2\n" ] } ], "source": [ "# A teraz?\n", "print(next(g))\n", "print(next(g))\n", "print(next(g))" ] }, { "cell_type": "code", "execution_count": 117, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3\n", "5\n", "8\n", "13\n", "21\n", "34\n", "55\n", "89\n", "144\n", "233\n" ] } ], "source": [ "# Można tak\n", "for i in range(10):\n", " print(next(g))" ] }, { "cell_type": "code", "execution_count": 118, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "1\n", "2\n", "3\n", "5\n", "8\n", "13\n", "21\n", "34\n", "55\n", "89\n" ] } ], "source": [ "# Co teraz chcemy otrzymać?\n", "for v in whatdoido():\n", " if v > 100:\n", " break\n", " print(v)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "# Ten kod tworzy wszytkie k-elementowe kombinacje z iterowalnego obiektu \n", "# (np. listy, ciągu znaków). Są tutaj dwie fajne rzeczy.\n", "def combinations(iterable, k):\n", " # combinations('ABCD', 2) --> AB AC AD BC BD CD\n", " # combinations(range(4), 3) --> 012 013 023 123\n", " pool = tuple(iterable)\n", " print (pool)\n", " n = len(pool)\n", " if k > n:\n", " return\n", " indices = list(range(k))\n", " print(indices)\n", " yield tuple(pool[i] for i in indices)\n", " while True:\n", " for i in reversed(range(k)):\n", " if indices[i] != i + n - k:\n", " break\n", " # Pierwsza fajna rzecz\n", " else:\n", " return\n", " indices[i] += 1\n", " for j in range(i+1, k):\n", " indices[j] = indices[j-1] + 1\n", " yield tuple(pool[i] for i in indices)\n", " \n", "pairs = combinations('ABCD', 2)\n", "print(pairs)\n", "# Druga fajna rzecz. Ale musimy uważać, przy tworzeniu generatora (return)\n", "for pair in pairs:\n", " print(pair)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "# Pierwsze trzy pary, które mają A i G w środku\n", "pairs = combinations('ABCDEFGH', 3)\n", "found = 0\n", "for pair in pairs:\n", " if 'A' in pair and 'G' in pair and found < 3:\n", " found += 1\n", " print(pair)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Build-in functions" ] }, { "cell_type": "code", "execution_count": 121, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 121, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Dwa przykłady poniżej są fajne, bo można np. wczytać sobie z jednego skrytpu drugi, \n", "# i go wykonać\n", "x=1\n", "eval('max([x,2,-2,3])')" ] }, { "cell_type": "code", "execution_count": 122, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-2.4492935982947064e-16\n" ] } ], "source": [ "exec('import math; print(math.sin(2*math.pi))')" ] }, { "cell_type": "code", "execution_count": 123, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "False\n", "True\n" ] } ], "source": [ "# Funkcje logiczne\n", "print(all([True, False, True]))\n", "print(any([True, False, True]))" ] }, { "cell_type": "code", "execution_count": 124, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "6\n", "1\n", "3\n" ] } ], "source": [ "# Funkcje matematyczne\n", "print(sum([1,2,3]))\n", "print(min([1,2,3]))\n", "print(max([1,2,3]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "# Inne funkcje matematyczne\n", "print(abs(-12))\n", "print(round(3.14159, 3))" ] }, { "cell_type": "code", "execution_count": 125, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "12.0\n", "12\n" ] } ], "source": [ "# Pamiętamy? Konwersja w pythonie jest łatwa.\n", "print(float(12))\n", "print(int(12.7))" ] }, { "cell_type": "code", "execution_count": 126, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "123\n", "[1, 2, 3]\n" ] } ], "source": [ "print(str(123))\n", "print(str([1,2,3]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "# Znak -> numer w unicode i na odwrót. \n", "print(ord('a'))\n", "print(chr(98))" ] }, { "cell_type": "code", "execution_count": 127, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n" ] } ], "source": [ "# Fajna funkcja. Do debugowania\n", "print(type('ala ma kota'))\n", "print(type([1,2,3]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Global" ] }, { "cell_type": "code", "execution_count": 128, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "# Trochę o zmiennych globalnych. \n", "text = 'ala ma kota'\n", "\n", "def a():\n", " print('a: ' + text) \n", "def b():\n", " print('b: ' + text)\n", " text = 'ala ma psa' " ] }, { "cell_type": "code", "execution_count": 129, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a: ala ma kota\n" ] } ], "source": [ "# Wynik?\n", "a()" ] }, { "cell_type": "code", "execution_count": 130, "metadata": {}, "outputs": [ { "ename": "UnboundLocalError", "evalue": "local variable 'text' referenced before assignment", "output_type": "error", "traceback": [ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", "\u001B[0;31mUnboundLocalError\u001B[0m Traceback (most recent call last)", "\u001B[0;32m\u001B[0m in \u001B[0;36m\u001B[0;34m()\u001B[0m\n\u001B[1;32m 1\u001B[0m \u001B[0;31m# Wynik?\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m----> 2\u001B[0;31m \u001B[0mb\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m", "\u001B[0;32m\u001B[0m in \u001B[0;36mb\u001B[0;34m()\u001B[0m\n\u001B[1;32m 5\u001B[0m \u001B[0mprint\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m'a: '\u001B[0m \u001B[0;34m+\u001B[0m \u001B[0mtext\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 6\u001B[0m \u001B[0;32mdef\u001B[0m \u001B[0mb\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m----> 7\u001B[0;31m \u001B[0mprint\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m'b: '\u001B[0m \u001B[0;34m+\u001B[0m \u001B[0mtext\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 8\u001B[0m \u001B[0mtext\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;34m'ala ma psa'\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", "\u001B[0;31mUnboundLocalError\u001B[0m: local variable 'text' referenced before assignment" ] } ], "source": [ "# Wynik?\n", "b()" ] }, { "cell_type": "code", "execution_count": 131, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "c: ala ma kota\n", "ala ma psa\n" ] } ], "source": [ "# Zmienne globalne są niebezpieczne. Python chce, żebyśmy mu dali znać,\n", "# że wiemy co robimy :)\n", "text = 'ala ma kota'\n", "def c():\n", " global text\n", " print('c: ' + text)\n", " text = 'ala ma psa'\n", "\n", "c()\n", "print(text)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Comprehensions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Lists" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "# To są fajne rzeczy. Warto zapamiętać - super oszczędność kodu!\n", "# Jakby wyglądało 'klasyczne' przeniesienie alementow jednej listy do drugiej + coś jeszcze\n", "\n", "arr = [0,1,2,3,4,5]\n", "new = []\n", "for a in arr:\n", " new.append('A' + str(a))\n", "new" ] }, { "cell_type": "code", "execution_count": 132, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['A0', 'A1', 'A2', 'A3', 'A4', 'A5']" ] }, "execution_count": 132, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# W pythonie można tak:\n", "\n", "arr = [0,1,2,3,4,5]\n", "new = ['A' + str(a) for a in arr]\n", "new" ] }, { "cell_type": "code", "execution_count": 133, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['A0', 'A2', 'A4']" ] }, "execution_count": 133, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Można dodać warunek. Czyli ogólnie: [funkcja for if]\n", "arr = [0,1,2,3,4,5]\n", "new = ['A' + str(a) for a in arr if a % 2 == 0]\n", "new" ] }, { "cell_type": "code", "execution_count": 135, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 135, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Co to robi?\n", "arr = [0,13,2,4,11]\n", "sum([1 for a in arr if a % 2 == 0])" ] }, { "cell_type": "code", "execution_count": 138, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['to', 'jest', 'krótki', 'text', 'nie', 'na', 'temat']" ] }, "execution_count": 138, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Chcemy wszystkie pierwsze litery wyrazów zamienić na wielkie\n", "text = 'to jest krótki text nie na temat'\n", "splitted = text.split()\n", "splitted" ] }, { "cell_type": "code", "execution_count": 139, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['To', 'Jest', 'Krótki', 'Text', 'Nie', 'Na', 'Temat']" ] }, "execution_count": 139, "metadata": {}, "output_type": "execute_result" } ], "source": [ "big = [x[0].upper() + x[1:] for x in splitted]\n", "big" ] }, { "cell_type": "code", "execution_count": 140, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'To Jest Krótki Text Nie Na Temat'" ] }, "execution_count": 140, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Trochę długaśne. Swoją drogą - fajne wykorzystanie str.join.\n", "\" \".join(big)" ] }, { "cell_type": "code", "execution_count": 141, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "To Jest Krótki Text Nie Na Temat\n" ] } ], "source": [ "# Można to zrobić krócej:\n", "text = 'to jest krótki text nie na temat'\n", "print(\" \".join([x[0].upper() + x[1:] for x in text.split()]))" ] }, { "cell_type": "code", "execution_count": 142, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[0, 1, 1, 0], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 0, 1]]\n", "[[1, 0, 0, 1], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 1, 0]]\n" ] } ], "source": [ "# Co, gdybyśmy chcieli coś zrobić, z każdą komórka 2d macierzy?\n", "\n", "m = [[0,1,1,0],\n", " [1,0,1,0],\n", " [0,1,0,1],\n", " [1,0,0,1]]\n", "nm = [[1 - cell for cell in row] for row in m]\n", "print(m)\n", "print(nm)" ] }, { "cell_type": "code", "execution_count": 143, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'chemia': 6, 'fizyka': 6, 'matematyka': 10}" ] }, "execution_count": 143, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Tutaj pamietamy o klamrach \n", "# Co to robi?\n", "przedmioty = ('matematyka', 'fizyka', 'chemia')\n", "slownik = {p: len(p) for p in przedmioty}\n", "slownik" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Classes" ] }, { "cell_type": "code", "execution_count": 144, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "28.274333882308138\n" ] } ], "source": [ "# Krótko omówimy klasy (tak, python jest obiektowy)\n", "# __init__, self\n", "\n", "class Circle:\n", " \n", " def __init__(self, radius):\n", " self.radius = radius \n", " self.costam = 2\n", " \n", " def area(self):\n", " from math import pi\n", " self.size = pi * self.radius**2\n", " return self.size\n", " \n", " def set_radius(self, radius):\n", " self.radius = radius \n", " \n", "c = Circle(3)\n", "print(c.area())\n", "c.set_radius(5) " ] }, { "cell_type": "code", "execution_count": 145, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "5\n" ] } ], "source": [ "print(c.radius)" ] }, { "cell_type": "code", "execution_count": 147, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 147, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# W pythonie nie ma '{ }' więc jak zrobić pustą klasę?\n", "# Pamiętamy, że w pythonie nie trzeba deklarować.\n", "# Wynik?\n", "\n", "class Container:\n", " pass\n", "\n", "def compute(container):\n", " return container.size**2\n", "\n", "c = Container\n", "c.size = 2;\n", "\n", "compute(c)" ] }, { "cell_type": "code", "execution_count": 148, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'kck'" ] }, "execution_count": 148, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Atrybuty 'statyczne' i dla instancji.\n", "class Przedmiot:\n", " acoto = 12\n", " alefajnie = 2\n", " def __init__(self, nazwa):\n", " self.nazwa = nazwa\n", " \n", " \n", "p = Przedmiot('kck')\n", "p.nazwa" ] }, { "cell_type": "code", "execution_count": 149, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "12\n", "2\n", "12\n", "5\n" ] } ], "source": [ "print(p.acoto)\n", "print(Przedmiot.alefajnie)\n", "print(Przedmiot.acoto)\n", "Przedmiot.acoto = 5\n", "print(Przedmiot.acoto)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "# Wygląda brzydko. A jak robiliśmy print(lista) to było ładnie. \n", "print(p)" ] }, { "cell_type": "code", "execution_count": 150, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Przedmiot o nazwie KCK\n" ] } ], "source": [ "# Można temu zaradzić\n", "class Przedmiot: \n", " def __init__(self, nazwa):\n", " self.nazwa = nazwa\n", " \n", " def __repr__(self):\n", " return 'Przedmiot o nazwie ' + self.nazwa\n", " \n", "p = Przedmiot('KCK')\n", "print(p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Duck typing" ] }, { "cell_type": "code", "execution_count": 164, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "50.26548245743669" ] }, "execution_count": 164, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "class Circle:\n", " def __init__(self, radius):\n", " self.radius = radius \n", " def area(self):\n", " from math import pi\n", " return pi * self.radius**2\n", "\n", "class Square:\n", " def __init__(self, w):\n", " self.w = w\n", " def area(self):\n", " return self.w**2\n", " \n", "class Line:\n", " pass\n", " \n", "def get_shape():\n", " from random import choice\n", " return choice([Square(4), Circle(4), Line()])\n", " \n", "shape = get_shape()\n", "shape.area()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Files" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "# Pisanie do pliku jest proste\n", "f = open('test.txt','w')\n", "for i in range(6):\n", " f.write('To jest linia {}\\n'.format(i))\n", "f.close()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "cat test.txt" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "# Czytanie też. Jak iterujemy plik, to czytamy linie.\n", "f = open('test.txt')\n", "for line in f:\n", " print(line.strip())\n", "f.close()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "# Można tak\n", "with open('test.txt') as f:\n", " for line in f:\n", " print(line.strip())" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "# Można od razu wczytac wsystkie linie i dalej używać.\n", "with open('test.txt') as f:\n", " lines = f.readlines()\n", "lines[1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "http://www.learnpython.org/en/Welcome " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "https://www.hackerrank.com/domains/python/py-introduction" ] }, { "cell_type": "code", "execution_count": 166, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 166, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAT8AAAEyCAYAAACMONd1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt81PWd7/HXJyEh3K/hlhDCVURAiBFUELXVFq0FwbaL\nvWqr9JzWPdvttufo7h4fXfs4p7t7zuluz+P42DVStdqt1Nag2NJS29oGUARMQAREwxAgkwDhfs9t\nPuePjDpNAxlgkt9c3s/HIw/n95uvzNsfk7czv5nv92fujohIpskKOoCISBBUfiKSkVR+IpKRVH4i\nkpFUfiKSkVR+IpKRVH4ikpFUfiKSkVR+IpKRegT1wEOHDvXi4uKgHl5E0tSbb755yN3zOxsXWPkV\nFxezadOmoB5eRNKUme2JZ5ze9opIRlL5iUhGUvmJSEZS+YlIRlL5iUhGUvmJSEZS+YlIRoqr/Mxs\nvpntNLNqM3uog/vHmNnvzOwtM/uDmRUmPqqISOJ0Wn5mlg08BtwOTAHuMbMp7Yb9b+AZd58OPAp8\nL9FBRUQSKZ5XfrOAancPuXsTsBxY2G7MFOD30duvdnC/iMhF2XfkDMvWhIhEuuYia/FMbysA9sVs\n1wKz243ZAiwGfgAsAvqZ2RB3Pxw7yMyWAksBioqKLjWziKSpE+eaWfVWPeVVYTbsPgLAdeOGMLVg\nQMIfK1Fze78F/D8zuxeoAMJAa/tB7l4GlAGUlpbqmpkiQnNrhDXvNfBCZZjfbj9AY0uEcfl9+PbH\nr2DhjFEUDurdJY8bT/mFgdEx24XRfR9w9zraXvlhZn2Bu939WKJCikh6cXe21Z3ghcpaXt5Sx6FT\nTQzuk8uSa0ezuKSQ6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JdkzNLN/MBkZv9wJuo+385KvAp6LD2h/P94/zp4DfR19pB5HznZj/4Rlt59Fij2e3/727\n+8PuXujuxbR9gPF7d/8c3XU8u+PTnHh+gOdoe2vTTNv7/K/Q9n7+d8B7wG+Bwf7hp1mP0Xa+ZStQ\nmgRZn41meSv6lzQyZvzfRbPuBG7vxpxzaXtL+xawOfpzR7Id1wvkTKpjCkwHqqJ53gYeie4fR1v5\nVgM/A3pG9+dFt6uj948LOOfvo8fzbeDHfPiJcKC/T9EMN/Php73dcjw1vU1EMlKyv+0VEekSKj8R\nyUgqPxHJSCo/EclIKj8RyUgqPxHJSCo/EclI/x9sX+0I1sdegwAAAABJRU5ErkJggg==\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "\n", "plt.figure(figsize=(5, 5))\n", "plt.plot([100,200,300,400],[0.1,0.2,0.8,0.9])\n", "#plt.savefig('myplot.pdf')\n", "#plt.close()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [] } ], "metadata": { "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.8.8" } }, "nbformat": 4, "nbformat_minor": 4 }