Академический Документы
Профессиональный Документы
Культура Документы
WWW.PENTALOG.COM
2
WWW.PENTALOG.COM
Python is an interpreted high-level programming
language for general-purpose programming.
Created by Guido van Rossum and first
released in 1991, Python has a design philosophy
that emphasizes code readability, notably using
significant whitespace. It provides constructs that
enable clear programming on both small and
large scales.
WWW.PENTALOG.COM
- easy to learn
- powerful programming language
- efficient high-level data structures
- simple but effective approach to OOP
- elegant syntax
- dynamic typing
- scripting and rapid application development
WWW.PENTALOG.COM
Guido van Rossum is a
Dutch programmer best known
as the author of the Python
programming language, for
which he is the "Benevolent
Dictator For Life" (BDFL).
From 2005 to December 2012,
he worked at Google, where
he spent half of his time
developing the Python
language. In January 2013, he
started working for Dropbox.
WWW.PENTALOG.COM
Monty Python were a British surreal comedy group who
created their sketch comedy show Monty Python's Flying
Circus, which first aired on the BBC in 1969.
WWW.PENTALOG.COM
Who uses python?
https://realpython.com/world-class-companies-using-python/
https://stackshare.io/python
https://www.python.org/about/success/
WWW.PENTALOG.COM
Installing python (Windows)
WWW.PENTALOG.COM
pip, pypi.org
youtube-dl
requests
flask
ipython
WWW.PENTALOG.COM
Editors & IDEs
IDLE
Vim, Emacs
Atom, Visual Studio Code
Notepad++
Sublime Text
PyCharm
10
WWW.PENTALOG.COM
Sublime Text
< 10 MB
Settings: tabs to spaces
File: Open Folder
View: sidebar, minimap
View: layout 1, 2, 3, 4
Plugins: Anaconda
11
WWW.PENTALOG.COM
Python Syntax
12
WWW.PENTALOG.COM
Variables, Data Types
13
WWW.PENTALOG.COM
Boolean operations
and
or
not
14
WWW.PENTALOG.COM
Console Input/Output
print('Some text')
print(1024)
print(question, answer)
name = input('Your name:')
age = int(input('Your age:'))
15
WWW.PENTALOG.COM
Conditionals
16
WWW.PENTALOG.COM
Looping with while
17
WWW.PENTALOG.COM
Data Structures
18
WWW.PENTALOG.COM
Data Structures
19
WWW.PENTALOG.COM
Lists
a = [1, 2, 3, 4, 5]
print(a)
print(a[0], a[-1], a[1:2])
del a[0]
a.append('x')
has_item = 4 in a
20
WWW.PENTALOG.COM
Looping with for
21
WWW.PENTALOG.COM
List comprehension
22
WWW.PENTALOG.COM
Dictionaries
d = {'k': 'value'}
has_key = 'k' in d
value = d['k']
other_value = d.get('k2', 'missing')
d['k3'] = 'some value'
del d['k']
23
WWW.PENTALOG.COM
Tuples
24
WWW.PENTALOG.COM
Named Tuples
from collections import namedtuple
p = Point(1, 2, 3)
c = Color(r=100, g=200, b=250)
25
WWW.PENTALOG.COM
Files
26
WWW.PENTALOG.COM
File I/O
f = open('data.txt', 'r')
data = f.read()
f.close()
with open('data.txt') as f:
data = f.read()
27
WWW.PENTALOG.COM
Functions
28
WWW.PENTALOG.COM
Functions
29
WWW.PENTALOG.COM
Classes and OOP
30
WWW.PENTALOG.COM
Classes
class Example:
def __init__(self, x):
self.x = x
def show_info(self):
print('Example:', self.x)
ex = Example(3.14159) # object
ex.show_info()
31
WWW.PENTALOG.COM
Classes
@property
@classmethod
@staticmethod
def __repr__(self):
# ...
32
WWW.PENTALOG.COM
OOP
Abstraction
Encapsulation
Inheritance
Polymorphism
Duck Typing
33
WWW.PENTALOG.COM
Design Patterns
34
WWW.PENTALOG.COM
Design Patterns
Iterator
__iter__, __next__, StopIteration
Generator
yield
@Decorator
35
WWW.PENTALOG.COM
Modules and Packages
36
WWW.PENTALOG.COM
Modules, Packages
# some_module.py
# some_package/__init__.py
import some_module
import some_package
from some_module import SomeClass, some_fn
if __name__ == '__main__':
# ...
37
WWW.PENTALOG.COM
Standard Library
38
WWW.PENTALOG.COM
Standard Library
39
WWW.PENTALOG.COM
Threads & Processes
import threading
Thread, start, join, target, Lock
import multiprocessing
Process, start, join, target, Lock
40
WWW.PENTALOG.COM
Unit Testing
import unittest
class TestMath(unittest.Testcase):
def test_add_with_zero(self):
result = 42 + 0
self.assertEquals(result, 42)
41
WWW.PENTALOG.COM
Errors and Exceptions
42
WWW.PENTALOG.COM
Errors & Exceptions
try/except/finally
raise
43
WWW.PENTALOG.COM
Web Development
44
WWW.PENTALOG.COM
Flask
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello, WWW!'
app.run(host='0.0.0.0', port=5000)
45
WWW.PENTALOG.COM
HTML
<html>
<head>
<meta charset="UTF-8"> <meta name="viewport" …
<title> … </title>
<style> CSS </style>
</head>
<body>
<h1> … </h1> <p>...</p> <img src=".." width="...">
<form method=".."> <input name=".." type=".."> </form>
</body>
</html>
46
WWW.PENTALOG.COM
CSS
p {
background-color: silver;
border: 1px red dotted;
color: black;
display: block;
font-family: sans-serif;
font-size: 16px;
margin: 10px;
padding: 4px;
text-align: justify;
}
47
WWW.PENTALOG.COM
RDBMS, SQL, sqlite3
48
WWW.PENTALOG.COM
SQL & RDBMS
CREATE
ALTER
DROP
SELECT
INSERT
UPDATE
DELETE
49
WWW.PENTALOG.COM
SQL & RDBMS
PK
Index
FK
One-to-many
Many-to-many
junction table
50
WWW.PENTALOG.COM
sqlite3
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
conn.close()
51
WWW.PENTALOG.COM
Git
git config
git init
git clone
git diff
git add
git commit -m "Verb regarding the changes"
52
WWW.PENTALOG.COM
Heroku
heroku login
heroku create
Procfile
web: waitress-serve server:app
53
WWW.PENTALOG.COM
What’s next?
54
WWW.PENTALOG.COM
Life-Long Learning
55
WWW.PENTALOG.COM
Flask
https://youtube.com/playlist?list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH
56
WWW.PENTALOG.COM
Django
https://www.djangoproject.com/
57
WWW.PENTALOG.COM
Q&A
58
WWW.PENTALOG.COM
59
WWW.PENTALOG.COM