Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédenteDernière révisionLes deux révisions suivantes |
python:bases:fonction [2022/09/03 10:21] – [1.3 L'instruction pass] phil | python:bases:fonction [2024/02/29 08:39] – [Python - Les fonctions] phil |
---|
===== Python - Les fonctions ===== | ===== Python - Les fonctions ===== |
| |
[Mise à jour le : 14/6/2022] | [Mise à jour le : 29/2/2024] |
| |
* **Sources** | * **Sources** |
| |
* **Ressources** | * **Ressources** |
| * <html><a href="https://www.pythonmorsels.com/built-in-functions-in-python/" target="_blank">Fonctions intégrées Python à connaître</a></html> |
* **Real Python** : <html><a href="https://realpython.com/python-main-function/" target="_blank">Defining Main Functions in Python</a></html> | * **Real Python** : <html><a href="https://realpython.com/python-main-function/" target="_blank">Defining Main Functions in Python</a></html> |
| |
| |
=== 1.1 Forme simple de la déclaration et de l'appel (ordonnée)=== | === 1.1 Forme simple de la déclaration et de l'appel (ordonnée)=== |
> Dans cette forme, les arguments sont dits:"positionnels" car leur position lors de l'appel doit correspondre à la position des paramètres dans l'en-tête de la fonction. | <callout type="info" icon="true">Dans cette forme, les arguments sont dits:"**positionnels**" car leur position lors de l'appel doit correspondre à la position des paramètres dans l'en-tête de la fonction.</callout> |
| |
<code python *.py> | <code python *.py> |
{{ :python:docstring.png?nolink&500 |}} | {{ :python:docstring.png?nolink&500 |}} |
| |
<note tip>Les arguments peuvent être passés dans un** ordre quelconque** si on précise le nom des paramètres.</note> | <callout type="tip" icon="true">Les arguments peuvent être passés dans un** ordre quelconque** si on précise le nom des paramètres.</callout> |
| |
// Exemple// | // Exemple// |
</code> | </code> |
| |
<note important>Un module **<nowiki>__name__</nowiki>** est égal à '**<nowiki>__main__</nowiki>**' lorsqu'il est lu à partir d'une entrée standard, d'un script ou d'une invite interactive.</note> | <callout type="warning" icon="true">Un module **<nowiki>__name__</nowiki>** est égal à '**<nowiki>__main__</nowiki>**' lorsqu'il est lu à partir d'une entrée standard, d'un script ou d'une invite interactive.</callout> |
| |
* **//Bonnes pratiques//** | * **//Bonnes pratiques//** |
* <html><a href="https://realpython.com/python-lambda/" target="_blank">How to Use Python Lambda Functions</a></html> | * <html><a href="https://realpython.com/python-lambda/" target="_blank">How to Use Python Lambda Functions</a></html> |
* <html><a href="https://realpython.com/run-python-scripts/" target="_blank">How to Run Your Python Scripts</a></html> | * <html><a href="https://realpython.com/run-python-scripts/" target="_blank">How to Run Your Python Scripts</a></html> |
| * <html><a href="https://realpython.com/python-sum-function/" target="_blank">Python's sum(): The Pythonic Way to Sum Values</a></html> |
| * <html><a href="https://realpython.com/len-python-function/" target="_blank">Using the len() Function in Python</a></html> |
| * <html><a href="https://realpython.com/python-min-and-max/" target="_blank">Python's min() and max(): Find Smallest and Largest Values</a></html> |
| * <html><a href="https://realpython.com/python-range/" target="_blank">The Python range() Function (Guide)</a></html> |
| |
---- | ---- |