English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutoriel de base Python

Contrôle de flux Python

Fonctions en Python

Types de données en Python

Opérations de fichiers Python

Objets et classes Python

Dates et heures Python

Connaissances avancées Python

Manuel de référence Python

Introduction à Python

Python est un langage de programmation multiplateforme, ce qui signifie qu'il peut fonctionner sur Windows, MacOS, Linux et d'autres plateformes, et a même été porté sur les machines virtuelles Java et .NET. Il est gratuit et open source.

Même si la plupart des Linux et Mac sont préinstallés avec Python aujourd'hui, cette version peut être obsolète. Par conséquent, installer la dernière version est toujours une bonne idée.

Le moyen le plus simple d'exécuter Python est

Le moyen le plus simple d'exécuter Python est d'utiliserThonny IDE. 

Thonny IDE est fourni avec la dernière version捆绑 de Python. Par conséquent, vous n'avez pas besoin d'installer Python individuellement.

Suivez les étapes suivantes pour exécuter Python sur votre ordinateur.

  1. TéléchargerThonny IDE.

  2. Exécutez le programme d'installation pour installer Thonny sur votre ordinateur.

  3. Aller àFichier > Nouveau. Ensuite, enregistrez le fichier avec l'extension .py. Par exemple hello.py, example.py, etc.
    Vous pouvez donner n'importe quel nom au fichier. Cependant, le nom du fichier doit commencer par.pyFin 

  4. Écrivez du code Python dans le fichier et enregistrez-le.

  5. Ensuite, allez àRun > Exécuter le script actuelOr click directlyF5Pour l'exécuter.

Installer Python individuellement

Si vous ne souhaitez pas utiliser Thonny, suivez la méthode suivante pour installer et exécuter Python sur votre ordinateur.

  1. TéléchargerLa dernière version de Python.

  2. Exécutez le fichier de programme d'installation et installez Python selon les étapes suivantes:
    Sélectionnez lors du processus d'installationAjouter Python aux variables d'environnementCela ajoutera Python aux variables d'environnement, et vous pourrez exécuter Python à partir de n'importe quel endroit de l'ordinateur.
    De plus, vous pouvez choisir le chemin d'installation de Python.

Une fois le processus d'installation terminé, vous pouvez exécuter Python.

1Exécuter Python en mode immédiat

Après l'installation de Python, tapez python dans la ligne de commande pour appeler l'interpréteur en mode immédiat. Vous pouvez directement saisir du code Python et appuyer sur la touche Entrée pour obtenir la sortie.

Try to enter,1 + 1Then press Enter. We get2as output. This prompt can be used as a calculator. To exit this mode, press Enter.

2Run Python in an integrated development environment (IDE)

We can use any text editor software to write Python script files.

We just need to save it with the .py extension. However, using an IDE can make our lives easier. An IDE is a software that provides programmers with useful features such as code hints, syntax highlighting and checking, file browser, etc., for application development.

By the way, when you install Python, you will also install a program calledIDLEIDE. You can use it to run Python on your computer. It is a good IDE for beginners.

When you open IDLE, an interactive Python Shell will open.


Now, you can create a new file and save it as.pyextension. For example,hello.py

Write Python code in the file and save it. To run the file, go toRun > Run module  Or click directlyF5.

Your first Python program

Now that we have started and run Python, we can write our first Python program.

Let's create a very simple program named "Hello World!". "Hello, World!" is a simple program that outputs text to the screen. Because it is a very simple program, it is often used to introduce beginners to a new programming language.

Type the following code in any text editor or IDE and save it as helloWorld.py

print("Hello world!")

Then, run the file. You will get the following output.

Hello world!

Congratulations! You have just written your first program in Python.

As we can see, this is very easy. This is the beauty of the Python programming language.