Table des matières

,

Python cours formation

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

Voir :

Formations :

Apprendre en ligne

Bases :

Avancé :

Linter / Formater :

Gérer les exceptions et les erreurs :

Les Libs:

P.O.O.

La stdlib - Parcours de quelques modules phares :

Docker / Containers :

Aller plus loin Présentation des objets et fonctions avancés

Les fonctions

def create_hello_world_message(name : str) -> str:
    """
    Creates a personalized greeting message for the given name.
 
    Parameters:
        - name (str) : The name for which the message is created.
 
    Returns:
        - hello_world_message (str) : A personalized greeting message for the given name.
 
    Raises:
        - ValueError : If the given name is empty or None.
    """
 
    if not name:
 
        raise ValueError
 
    hello_world_message = f'Hello World, {name}!'
 
    print(f'name                : { name }')
    print(f'hello_world_message : { hello_world_message }')
 
    return hello_world_message

Import

import os
import sys
sys.path.append(os.path.dirname(os.getcwd()))
 
import plop

Sciences - math

from sympy import symbols, Eq, solve
 
B, G = symbols('B G')
eq1 = Eq(B, 0.3 * B + 5 * G)
eq2 = Eq(100 * B + 200 * G, 1000)
solution = solve(eq1, eq2), (B, G))
solution[B]

Mutable / immutable

Voir aussi : deepcopy

lst=[1,2,3];
print(list(map(lambda x: [x],lst)));

Autres

import random
random.randint(1,9)
export PYTHONUNBUFFERED=1

Linter

Flake8

ansible-csv-inventory.py:30:80: E501 line too long (82 > 79 characters)

Pour ignorer l'erreur

tox.ini

[flake8]
extend-ignore = E501

Autres

$ ansible-test sanity --list-tests
action-plugin-docs
ansible-doc
changelog
compile
empty-init
ignores
import
line-endings
no-assert
no-get-exception
no-illegal-filenames
no-smart-quotes
pep8
pslint
pylint
replace-urlopen
runtime-metadata
shebang
shellcheck
symlinks
use-argspec-type-path
use-compat-six
validate-modules
yamllint