Skip to content
Snippets Groups Projects
Select Git revision
  • 15d9b073db151ddfa99e235dec655acec30affc7
  • master default protected
  • workshop
  • v1.0
4 results

PITCHME.md

Blame
  • user avatar
    Bodor Máté authored
    15d9b073
    History

    Python3 alapok

    import this
    

    The Zen of Python, by Tim Peters

      @size[24px](
    1. Beautiful is better than ugly.
    2. ) @size[24px](
    3. Explicit is better than implicit.
    4. ) @size[24px](
    5. Simple is better than complex.
    6. ) @size[24px](
    7. Complex is better than complicated.
    8. ) @size[24px](
    9. Flat is better than nested.
    10. ) @size[24px](
    11. Sparse is better than dense.
    12. ) @size[24px](
    13. Readability counts.
    14. ) @size[24px](
    15. Special cases aren't special enough to break the rules.
    16. ) @size[24px](
    17. Although practicality beats purity.
    18. ) @size[24px](
    19. Errors should never pass silently.
    20. ) @size[24px](
    21. Unless explicitly silenced.
    22. ) @size[24px](
    23. In the face of ambiguity, refuse the temptation to guess.
    24. )
      @size[24px](
    1. There should be one-- and preferably only one --obvious way to do it.
    2. ) @size[24px](
    3. Although that way may not be obvious at first unless you're Dutch.
    4. ) @size[24px](
    5. Now is better than never.
    6. ) @size[24px](
    7. Although never is often better than right now.
    8. ) @size[24px](
    9. If the implementation is hard to explain, it's a bad idea.
    10. ) @size[24px](
    11. If the implementation is easy to explain, it may be a good idea.
    12. ) @size[24px](
    13. Namespaces are one honking great idea -- let's do more of those!
    14. )

    Története

    • Guido van Rossum
    • 1991-ben jött létre
    • Magas szintű programozási nyelv

    Note:

    • BDFL (Benevolent dictator for life)
    • Monty Python, karácsony
    • könnyen olvasható, tanulható, gyors fejlesztés
    • lassú

    Interpretált

    • A kódot egy értelmező dolgozza fel
    • Nem kell fordítani
    • Platformfüggetlen

    Note:


    Miért szeretjük a pythont?

    Note:

    • Magasszintű:
      • Könnyen tanulható, gyors fejlesztés
    • Interpretált:
      • Bárhol lefut, nem kell lefordítani

    Python is awsome!


    Tökéletes?!

    +++

    Tökéletes?!

    NEM!

    +++

    Tökéletes?!

    • Viszonylag lassú
    • Nagy memóriaigény

    Note:

    +++

    C++ vs Python3

    Note: https://en.wikipedia.org/wiki/N-body_simulation

    Csomagok

    • Webfejlesztés:
      • Django
      • Flusk
      • Requests

    +++

    • IT Security:
      • Scapy
      • Nmap

    +++

    • AI:
      • TensorFlow
      • Keras

    +++

    • Data Science:
      • Pandas
      • StatsModels
      • NumPy

    +++

    • GUI:
      • PyQt
      • Tkinter
      • Flexx

    +++

    • Data visualization
      • matplotlib
      • Plotly
      • geoplotlib Note:

    Pip

    • Csomagkezelő
      • Egy helyen van minden
      • Könnyen használható

    Note:

    • könnyen használható
      • C++ ban jóval nehezebb lib import

    +++

    pip install <package>

    Virtualenv

    • Saját környezet minden projekthez

    Note:

    • Dependency, egy csomag több verzió

    +++

    • Windows:
    python -m venv venv
    venv\Scripts\activate.bat

    +++

    • Linux:
    python3 -m venv venv
    source venv/bin/activate

    Flake8

    • Linter
    • Segít jobb kódot írni:
      • Syntax error
      • Typo
      • Rossz formázás
    • pep8(Style Guide)
    pip install flake8
    flake8 <filename>

    Note:

    • Style Guide
      • átlátható
      • egységes
      • kevesebb merge conflict

    Black

    • Atomatikusan formázza a kódot.
    pip install black
    black <filename>

    Hello World

    +++

    print("Hello World!")
    

    +++

    pip install colorama
    from colorama import init
    from colorama import Fore, Back, Style
    
    init()
    print(Fore.RED + "some red text")
    print(Back.GREEN + "and with a green background")
    print(Style.DIM + "and in dim text")
    print(Style.RESET_ALL)
    print("back to normal now")
    

    Szintaxis

    """This is the start of the program """
    while 1:
        print("Spam")
        answer = input("Press y for large fries ")
        if answer == "y":
            print("Large fries with spam, mmmm, yummy ")
            continue
        answer = input("Had enough yet? ")
        if answer == "y":
            break
    print("Have a ")
    print("nice day!")  # Bye bye
    

    Note:

    • Nincs sorvég jel
    • A kód blokkok indentálva vannak nincs kapcsoszárójel
      • 4 space
    • komment #, '''alam'''

    Változók

    • number (integer, floating point, complex)
    • boolean
    • string
    • list, tuple, dictionary, ...

    +++

    a = 2
    b = 3.2
    d = 2 + 4j
    x = False
    str = "string"
    str2 = str * 2
    str3 = str2 + "abc"
    
    print(a ** 3)
    print(b / 2)
    print(d * 2)
    print(x)
    print(str)
    print(str2)
    print(str3)
    

    Output

    8
    1.6
    (4+8j)
    False
    string
    stringstring
    stringstringabc

    List

    +++

    • Bármilyen típust tartalmazhat (általában egyforma)
    • Az elemek indexelhetőek
    • Módosítható(mutable)

    +++

    list = ["a", "b", "c", 1, 2, 3]
    for a in list:
        print(a)
    list[4] = 22
    list.append(50)
    del list[3]
    print(list[2:])
    

    Output:

    a
    b
    c
    1
    2
    3
    ['c', 22, 3, 50]

    Tuple

    +++

    • Ugyanaz, mint egy lista
    • De nem módosítható(immutable)

    +++

    tuple = ("a", "b", 3)
    item = tuple[2]
    for a in tuple:
        print(a)
    
    a, b, c = tuple
    print(c)
    
    tuple2 = (34, 56, "d")
    tuple3 = tuple + tuple2
    print(tuple3)
    

    Output:

    a
    b
    3
    
    3
    
    ('a', 'b', 3, 34, 56, 'd')

    Dictionary

    +++

    • Kulcs érték pár
    • A kulcs egyedi, érték bármi lehet

    +++

    dict = {"Name": "Zara", "Age": 10, "Class": "First"}
    
    dict["Age"] = 8
    for key, value in dict.items():
        print(key, " : ", value)
    del dict["Name"]
    print("Name" in dict)
    

    Output:

    Name  :  Zara
    Age  :  8
    Class  :  First
    False

    Set

    +++

    • Mint a lista, csak minden érték egyszer szerepelhet
    • Nem biztos, hogy sorban tárolja

    +++

    set = {1, 3, 5}
    print(1 in set)
    print(2 in set)
    set.add(2)
    set.update([6, 4])
    for a in set:
        print(a)
    

    Output:

    True
    False
    1
    2
    3
    4
    5
    6

    Függvények

    +++

    def fibonacci():
        if n == 0:
            return 0
        elif n == 1:
            return 1
        else:
            return fibonacci(n - 1) + fibonacci(n - 2)
    
    
    print(fibonacci(10))
    

    Output:

    55

    +++

    • Opciónális paraméter
    def fibonacci(n=10):
        if n == 0:
            return 0
        elif n == 1:
            return 1
        else:
            return fibonacci(n - 1) + fibonacci(n - 2)
    
    
    print(fibonacci())
    

    Output:

    55

    +++

    • Tetszőlegesen sok paraméter, list
    def minimum(first, *args):
        acc = first
        for x in args:
            if x < acc:
                acc = x
        return acc
    
    
    print(minimum(3, 4, 2, -8, 6))
    

    Output:

    -8

    +++

    • Tetszőlegesen sok paraméter, dictionary
    def bar(**kwargs):
        for key, value in kwargs.items():
            print(key, value)
    
    
    print(bar(Kutya="vau", Cica="miaaau"))
    

    Output:

    -8

    +++

    • Névszerinti paraméterátadás
    def print_rectangle(w=0, h=0, x=0, y=0):
        print("Rectangle")
        print("- size: {}×{}".format(w, h))
        print("- position: ({};{})".format(x, y))
    
    
    print_rectangle(20, 30, 40, 50)
    print_rectangle(x=10, w=19, h=25)
    

    Output:

    Rectangle
    - size: 20×30
    - position: (40;50)
    Rectangle
    - size: 19×25
    - position: (10;0)

    Alap beépített fgv-ek

    dir(__builtins__)
    

    +++


    Ciklusok


    While

    +++

    i = 1
    while i < 6:
        print(i)
        i += 1
    

    Output:

    1
    2
    3
    4
    5

    For(each)

    +++

    a = [1, 2, 3]
    for x in a:
        print(x)
    
    print("-")
    
    for x in range(1, 6, 2): # for (int i = 1; i < 6; i += 2)
        print(x)
    

    Output:

    1
    2
    3
    -
    1
    3
    5

    Elágazások

    +++

    b = False
    x = 3
    if not b and x <= 6:
        print("Hello")
    elif b or x > 5:
       print("World!")
    else:
       print("Hello World!")
    

    Output:

    Hello

    Osztályok

    +++

    class A:
        b = "Foo"
    
        def __init__(self):
            self.a = 1
    
        def print(self, str):
            for x in range(self.a):
                print(self.b, str)
    
    class B(A):
        def __init__(self, a):
            self.a = a
    
    a = A()
    a.print("Fighters")
    b = B(5)
    b.print(u"\u03C1" + " Fej")
    

    Output

    Foo Fighters
    Foo ρ Fej
    Foo ρ Fej
    Foo ρ Fej
    Foo ρ Fej
    Foo ρ Fej

    HF


    Dekorátor

    +++

    def my_decorator(func):
        def wrapper():
           print("Before")
           func()
           print("After")
    
        return wrapper
    
    @my_decorator
    def hello():
        print("Hello")
    

    Output:

    Before
    Hello
    After