Please enable JavaScript.
Coggle requires JavaScript to display documents.
Pyhton
https://github.com/python/cpython (Characteristics (Paradigms…
-
-
-
How Python works
-
Scope
LEGB Rules
Local -> Enclosed -> Global -> Built-in
Local - Names assigned in any way within a function (def or lambda), and not declared global in that function.
Enclosing function locals - Names in the local scope of any and all enclosing functions (def or lambda), from inner to outer.
Global (module) - Names assigned at the top-level of a module file, or declared global in a def within the file.
Built-in (Python) - Names preassigned in the built-in names module : open, range, SyntaxError ...
-
-
Language Drawbacks
Python is slower than C or C++, but it's more flexible.
-
Characteristics
-
-
-
Design philosophy that emphasizes code readability, notably using significant whitespace
-
Paradigms
- object-oriented
- imperative
- functional
- procedural
-
-
-
Tools
virtualenv
virtualenv is a tool to create isolated Python environments.
There are few commands and you can also pass python version when activating the env.
virtualenv -p python3 directory_name
source directory_name/bin/activate
-
-
-
Package Managers
-
pip
pip is a package management system used to install and manage software packages written in Python.
-
-
-
Implementations (Interpreter)
When people speak of Python they often mean not just the language but also the CPython implementation. Python is actually a specification for a language that can be implemented in many different ways.
-
Pypy
a Python interpreter implemented in a restricted statically-typed subset of the Python language called RPython.
Jython
a Python implementation that compiles Python code to Java bytecode which is then executed by the JVM (Java Virtual Machine).
-
Best Practices
-
-
-
-
LBYL - Look Before You Leap
Check for example if the file exist before trying to open it.
EAFP - Easy Ask Forgiveness Then Permission
Don't check if the file exist and show a message saying if some error raise
Data Types / Structure
int (Integers)
Ex.: 1, 100, 1000000
float (Floating point)
Ex.: 1.1, 200.22, 3000.0
-
list (Lists)
Ordered sequence of objects
Ex.: [10, "hello", 100.1]
dict (Dictionaries)
Unordered key:value paris
Ex.: {"name": "Gustavo", "age": 30}
tup (Tuples)
Ordered immutable sequence of objects
Ex.: (10, "hello", 100.1)
set (Sets)
Unordered collection of unique objects
Ex.: {"a", "b", 1, 2}
bool (Booleans)
Ex.: True, False
Module x Package
Module is a .py script file.
Package is a directory with one or a collection of .py scripts.
-