Nouveaux modules de Développement Informatique ajoutés régulièrement.
DevWebSol
Catégorie : Python

Python Introduction

Administrateur DevWebSol Vérifié
01 November, 2026 • ~4 min de lecture

Introduction

Python is a high-level programming language for general-purpose programming. It is an open source, interpreted, object-oriented programming language. Python was created by a Dutch programmer, Guido van Rossum. The name of the Python programming language was derived from a British sketch comedy series, Monty Python's Flying Circus. The first version was released on February 20, 1991. This 30 days of Python challenge will help you learn the latest version of Python, Python 3 step by step. The topics are broken down into 30 days, where each day contains several topics with easy-to-understand explanations, real-world examples, and many hands on exercises and projects.

This challenge is designed for beginners and professionals who want to learn python programming language. It may take 30 to 100 days to complete the challenge. People who actively participate in the telegram group have a high probability of completing the challenge.

This challenge is easy to read, written in conversational English, engaging, motivating and at the same time, it is very demanding. You need to allocate much time to finish this challenge. If you are a visual learner, you may get the video lesson on Washera YouTube channel. You may start from Python for Absolute Beginners video. Subscribe the channel, comment and ask questions on YouTube videos and be proactive, the author will eventually notice you.

The author likes to hear your opinion about the challenge, share the author by expressing your thoughts about the 30DaysOfPython challenge. You can leave your testimonial on this link

Why Python ?

It is a programming language which is very close to human language and because of that, it is easy to learn and use. Python is used by various industries and companies (including Google). It has been used to develop web applications, desktop applications, system administration, and machine learning libraries. Python is a highly embraced language in the data science and machine learning community. I hope this is enough to convince you to start learning Python. Python is eating the world and you are killing it before it eats you.

Environment Setup

Installing Python

To run a python script you need to install python. Let's download python. If your are a windows user, click the button encircled in red.

installation sous Windows

If you are a macOS user, click the button encircled in red.

installation sous Windows

To check if python is installed write the following command on your device terminal.

python3 --version

Copy code to clipboard

Version Python

As you can see from the terminal, I am using Python 3.7.5 version at the moment. Your version of Python might be different from mine by but it should be 3.6 or above. If you manage to see the python version, well done. Python has been installed on your machine. Continue to the next section.

Python Shell

Python is an interpreted scripting language, so it does not need to be compiled. It means it executes the code line by line. Python comes with a Python Shell (Python Interactive Shell). It is used to execute a single python command and get the result.

Python Shell waits for the Python code from the user. When you enter the code, it interprets the code and shows the result in the next line. Open your terminal or command prompt(cmd) and write:

python

Copy code to clipboard

Shell de script Python

The Python interactive shell is opened and it is waiting for you to write Python code(Python script). You will write your Python script next to this symbol >>> and then click Enter. Let us write our very first script on the Python scripting shell.

Script Python sur le shell Python

Well done, you wrote your first Python script on Python interactive shell. How do we close the Python interactive shell ? To close the shell, next to this symbol >>> write exit() command and press Enter.

Sortie du shell Python

Now, you know how to open the Python interactive shell and how to exit from it.

Python will give you results if you write scripts that Python understands, if not it returns errors. Let's make a deliberate mistake and see what Python will return.

Erreur de syntaxe non valide

As you can see from the returned error, Python is so clever that it knows the mistake we made and which was Syntax Error: invalid syntax. Using x as multiplication in Python is a syntax error because (x) is not a valid syntax in Python. Instead of (x) we use asterisk (*) for multiplication. The returned error clearly shows what to fix.

The process of identifying and removing errors from a program is called debugging. Let us debug it by putting * in place of x.

Correction d'une erreur de syntaxe

Our bug was fixed, the code ran and we got a result we were expecting. As a programmer you will see such kind of errors on daily basis. It is good to know how to debug. To be good at debugging you should understand what kind of errors you are facing. Some of the Python errors you may encounter are SyntaxError, IndexError, NameError, ModuleNotFoundError, KeyError, ImportError, AttributeError, TypeError, ValueError, ZeroDivisionError etc. We will see more about different Python error types in later sections.

Let us practice more how to use Python interactive shell. Go to your terminal or command prompt and write the word python.

Shell de script Python

The Python interactive shell is opened. Let us do some basic mathematical operations (addition, subtraction, multiplication, division, modulus, exponentiation).

Let us do some maths first before we write any Python code:

  • 2 + 3 = 5
  • 3 - 2 = 1
  • 3 * 2 = 6
  • 3 / 2 = 1.5
  • 3 ** 2 = 3 x 3 = 9

In python, we have the following additional operations:

  • 3 % 2 = 1 => which means finding the remainder
  • 3 // 2 = 1 => which means removing the remainder

Let us change the above mathematical expressions to Python code. The Python shell has been opened and let us write a comment at the very beginning of the shell.

A comment is a part of the code which is not executed by python. So we can leave some text in our code to make our code more readable. Python does not run the comment part. A comment in python starts with hash(#) symbol. This is how you write a comment in python

 # comment starts with hash
 # this is a python comment, because it starts with a (#) symbol

Copy code to clipboard

Mathématiques sur shell python

Before we move on to the next section, let us practice more on the Python interactive shell. Close the opened shell by writing exit() on the shell and open it again and let us practice how to write text on the Python shell.

Écriture d'une chaîne sur un shell Python

Installing Visual Studio Code

The Python interactive shell is good to try and test small script codes but it will not be for a big project. In real work environment, developers use different code editors to write codes. In this 30 days of Python programming challenge, we will use Visual Studio Code. Visual Studio Code is a very popular open source text editor. I am a fan of vscode and I would recommend to download visual studio code, but if you are in favor of other editors, feel free to follow with what you have.

Code de Visual Studio

If you installed visual studio code, let us see how to use it. If you prefer a video, you can follow this Visual Studio Code for Python Video tutorial

How to use visual studio code

Open the visual studio code by double clicking the visual studio icon. When you open it you will get this kind of interface. Try to interact with the labeled icons.

Code du studio visuel

Create a folder named 30DaysOfPython on your desktop. Then open it using visual studio code.

Projet d'ouverture sur Visual Studio

Ouverture d'un projet

After opening it, you will see shortcuts for creating files and folders inside of 30DaysOfPython project's directory. As you can see below, I have created the very first file, helloworld.py. You can do the same.

Création d'un fichier python

After a long day of coding, you want to close your code editor, right? This is how you will close the opened project.

Projet de clôture

Congratulations, you have finished setting up the development environment. Let us start coding.

Basic Python

Python Syntax

A Python script can be written in Python interactive shell or in the code editor. A Python file has an extension .py.

Python Indentation

Une indentation est un espace blanc dans un texte. Dans de nombreux langages, l'indentation est utilisée pour augmenter la lisibilité du code ; cependant, Python utilise l'indentation pour créer des blocs de code. Dans d'autres langages de programmation, les accolades sont utilisées pour créer des blocs de code au lieu de l'indentation. L’un des bugs courants lors de l’écriture de code Python est l’indentation incorrecte.

Erreur d'indentation

Commentaires

Les commentaires jouent un rôle crucial en améliorant la lisibilité du code et en permettant aux développeurs de laisser des notes dans leur code. En Python, tout texte précédé d'un symbole de hachage (#) est considéré comme un commentaire et n'est pas exécuté lorsque le code s'exécute.

Exemple : Commentaire sur une seule ligne

    # This is the first comment
    # This is the second comment
    # Python is eating the world

Copy code to clipboard

Exemple : Commentaire multiligne

Les guillemets triples peuvent être utilisés pour les commentaires multilignes s'ils ne sont pas attribués à une variable

"""This is multiline comment
multiline comment takes multiple lines.
python is eating the world
"""

Copy code to clipboard

Types de données

En Python, il existe plusieurs types de types de données. Commençons par les plus courants. Différents types de données seront abordés en détail dans d’autres sections. Pour l’instant, passons simplement en revue les différents types de données et familiarisons-nous avec eux. Vous n’avez pas besoin d’avoir une compréhension claire maintenant.

Nombre

  • Entier : nombres entiers (négatifs, nuls et positifs) Exemple: ... -3, -2, -1, 0, 1, 2, 3 ...
  • Flotteur : Nombre décimal Exemple ... -3,5, -2,25, -1,0, 0,0, 1,1, 2,2, 3,5 ...
  • Complexe Exemple 1 + j, 2 + 4j

Chaîne

Une collection d'un ou plusieurs caractères sous une citation simple ou double. Si une chaîne contient plus d’une phrase, nous utilisons une citation triple.

Exemple:

'Asabeneh'
'Finland'
'Python'
'I love teaching'
'I hope you are enjoying the first day of 30DaysOfPython Challenge'

Copy code to clipboard

Booléens

Un type de données booléen est soit une valeur Vrai, soit une valeur Faux. T et F doivent toujours être en majuscules.

Exemple:

    True  #  Is the light on? If it is on, then the value is True
    False # Is the light on? If it is off, then the value is False

Copy code to clipboard

Liste

La liste Python est une collection ordonnée qui permet de stocker différents éléments de type de données. Une liste est similaire à un tableau en JavaScript.

Exemple:

[0, 1, 2, 3, 4, 5]  # all are the same data types - a list of numbers
['Banana', 'Orange', 'Mango', 'Avocado'] # all the same data types - a list of strings (fruits)
['Finland','Estonia', 'Sweden','Norway'] # all the same data types - a list of strings (countries)
['Banana', 10, False, 9.81] # different data types in the list - string, integer, boolean and float

Copy code to clipboard

Dictionnaire

Un objet de dictionnaire Python est une collection non ordonnée de données dans un format de paire clé-valeur.

Exemple:

{
'first_name':'Asabeneh',
'last_name':'Yetayeh',
'country':'Finland',
'age':250,
'is_married':True,
'skills':['JS', 'React', 'Node', 'Python']
}

Copy code to clipboard

Tuple

Un tuple est une collection ordonnée de différents types de données comme une liste, mais les tuples ne peuvent pas être modifiés une fois créés. Ils sont immuables.

Exemple:

('Asabeneh', 'Pawel', 'Brook', 'Abraham', 'Lidiya') # Names

Copy code to clipboard

('Earth', 'Jupiter', 'Neptune', 'Mars', 'Venus', 'Saturn', 'Uranus', 'Mercury') # planets

Copy code to clipboard

Ensemble

Un ensemble est une collection de types de données similaires à une liste et à un tuple. Contrairement à la liste et au tuple, set n'est pas une collection ordonnée d'éléments. Comme en mathématiques, set in Python stocke uniquement des éléments uniques.

Dans les sections suivantes, nous détaillerons chaque type de données Python.

Exemple:

{2, 4, 3, 5}
{3.14, 9.81, 2.7} # order is not important in set

Copy code to clipboard

Vérification des types de données

Pour vérifier le type de données de certaines données/variables, nous utilisons la fonction type. Dans le terminal suivant, vous verrez différents types de données Python :

Vérification des types de données

Fichier Python

Ouvrez d’abord votre dossier de projet, 30DaysOfPython. Si vous n'avez pas ce dossier, créez un nom de dossier appelé 30DaysOfPython. Dans ce dossier, créez un fichier appelé helloworld.py. Maintenant, faisons ce que nous avons fait sur le shell interactif Python en utilisant le code Visual Studio.

Le shell interactif Python imprimait sans utiliser print mais sur le code Visual Studio pour voir notre résultat, nous devrions utiliser une fonction intégrée print(). La fonction intégrée print() prend un ou plusieurs arguments comme suit print('arument1', 'argument2', 'argument3'). Voir les exemples ci-dessous.

Exemple:

Le nom du fichier est helloworld.py

# Day 1 - 30DaysOfPython Challenge

print(2 + 3)             # addition(+)
print(3 - 1)             # subtraction(-)
print(2 * 3)             # multiplication(*)
print(3 / 2)             # division(/)
print(3 ** 2)            # exponential(**)
print(3 % 2)             # modulus(%)
print(3 // 2)            # Floor division operator(//)

# Checking data types
print(type(10))          # Int
print(type(3.14))        # Float
print(type(1 + 3j))      # Complex number
print(type('Asabeneh'))  # String
print(type([1, 2, 3]))   # List
print(type({'name':'Asabeneh'})) # Dictionary
print(type({9.8, 3.14, 2.7}))    # Set
print(type((9.8, 3.14, 2.7)))    # Tuple

Copy code to clipboard

Pour exécuter le fichier python, vérifiez l'image ci-dessous. Vous pouvez exécuter le fichier python soit en exécutant le bouton vert sur Visual Studio Code, soit en tapant python helloworld.py dans le terminal.

Exécution d'un script Python

🌕 Tu es incroyable. Vous venez de terminer le défi du premier jour et vous êtes sur la voie de la grandeur. Faites maintenant quelques exercices pour votre cerveau et vos muscles.

No comments: