1.4. Python Language¶

Figure 1.1. Python Logo¶
1.4.1. Rationale¶
Turing complete, general purpose language
Multi platform
Dynamic typing with automatic memory allocation and GC
Code readability and simplicity is important
White space are important
Everything is an object, but you can write functional code too
Standard language in Machine Learning and Data Science
Very good standard system library
Huge ecosystem of external open source libraries
Open Source created by non-profit Python Software Foundation
1.4.2. Which Version?¶
You should use newest official Python version
Source: https://devguide.python.org/#status-of-python-branches
Version |
PEP |
Status |
Release |
End-of-life |
Release Manager |
---|---|---|---|---|---|
3.11 |
TBA |
future |
2022-10-04 |
TBA |
Pablo Galindo Salgado |
3.10 |
TBA |
development |
2021-10-04 |
TBA |
Pablo Galindo Salgado |
Version |
PEP |
Status |
Release |
End-of-life |
Release Manager |
---|---|---|---|---|---|
3.9 |
features |
2020-10-05 |
TBA |
Łukasz Langa |
|
3.8 |
features |
2019-10-20 |
2024-10 |
Łukasz Langa |
|
3.7 |
bugfix |
2018-06-27 |
2023-06-27 |
Ned Deily |
|
3.6 |
security |
2016-12-23 |
2021-12-23 |
Ned Deily |
Version |
PEP |
Status |
Release |
End-of-life |
Release Manager |
---|---|---|---|---|---|
3.5 |
end of life |
2015-09-13 |
2020-09-13 |
Larry Hastings |
|
3.4 |
end of life |
2014-03-16 |
2019-03-16 |
Larry Hastings |
|
3.3 |
end of life |
2012-09-29 |
2017-09-29 |
Georg Brandl |
|
3.2 |
end of life |
2011-02-20 |
2016-02-20 |
Georg Brandl |
|
3.1 |
end of life |
2009-06-27 |
2012-04-09 |
Benjamin Peterson |
|
3.0 |
end of life |
2008-12-03 |
2009-01-13 |
Barry Warsaw |
|
2.7 |
end of life |
2010-07-03 |
2020-04-20 |
Benjamin Peterson |
|
2.6 |
end of life |
2008-10-01 |
2013-10-29 |
Barry Warsaw |
1.4.3. Why not Python 2?¶
1.4.4. Changes in Python 3¶
All strings are Unicode
In Python 3
print()
is a function, not a keywordChanges in standard library modules naming and location
New string formatting
1.4.5. Python Release Cycle¶
Since Python 3.9: PEP 602 -- Annual Release Cycle for Python
12 months (1 year) release cycle
18 months (1.5 year) of bugfix updates
42 months (3.5 year) of security updates

Figure 1.2. Python 12 months release cycle.¶
1.4.6. Scripts¶
Python files use
.py
as an extensionCompiled files are in
__pycache__
directoryPython also uses other extensions
Extension |
Description |
---|---|
|
Compiled source code (bytecode) |
|
Compiled Windows DLL file |
|
Compiled Windows file. Executable with |
|
cPythona source for C/C++ conversion |
|
zipapp compressed archive |
1.4.7. Python Console (REPL)¶
Read–Eval–Print Loop
Quickly test and evaluate code
Lines starts with
>>>
Line continuation starts with
...
Result is printed below
Open REPL with
python3
command in terminal
$ python3
3.8.2 (default, Mar 11 2020, 00:29:50)
[Clang 11.0.0 (clang-1100.0.33.17)]
Type "help", "copyright", "credits" or "license" for more information.
>>> print('Ehlo World!')
Ehlo World!
In documentation and books you may find >>>
and ...
at the beginning of code listing lines
>>> if True:
... print('yes')
... else:
... print('no')
yes
1.4.8. Jupyter¶
Open Source web application REPL
Very popular in Machine Learning and Data Science world
Create and share documents that contain live code, equations, visualizations and narrative text
Uses include: data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, etc
1.4.9. Python Developer Survey¶
1.4.10. Assignments¶
"""
* Assignment: About Environment
* Complexity: easy
* Lines of code: 0 lines
* Time: 3 min
English:
TODO: English Translation
Polish:
1. Stwórz plik o nazwie `about_env.py`
2. Użyj danych z sekcji "Given" (patrz poniżej)
3. Uruchom plik w swoim IDE (menu `Run -> Run... -> nazwa Twojego skryptu`)
4. Gdzie Python jest zainstalowany?
5. Czy korzystasz z "Virtualenv"?
6. Upewnij się, że w linijce z "Virtualenv" nie masz `None`
"""
# Given
import sys
import os
print(f'Python Executable: {sys.executable}')
print(f'Python Version: {sys.version}')
print(f'Virtualenv: {os.getenv("VIRTUAL_ENV")}')