learn-python-in10-days-extract
learn-python-in10-days-extract
11 avril 2024
Contents
1
CONTENTS 2
4
CONTENTS 5
6
Code Preview
The code employed in this book has been thoughtfully crafted uti-
lizing valuable tools and specific LaTeX packages. Here is an example
of code preview:
1 # define a string variable
3 print ( s )
7
Who is This Book For?
8
CONTENTS 9
your system.
[...]
Continue exploring the various aspects of Python each day, learning
gradually and applying your newly acquired knowledge. Have a great
journey into the world of Python!
Introduction
10
Chapter 1
11
CHAPTER 1. DAY 1: INSTALLING THE TOOLS 12
called IDLE by default. To launch it, simply type IDLE in the search
Once launched, you will see the following view of the user interface
excellent tool for beginners to get started and understand the workings
of Python:
CHAPTER 1. DAY 1: INSTALLING THE TOOLS 14
forward layout, with a text editor window where you can write and edit
Python code. Below the text editor, there is a Python shell window
where you can interactively execute Python code and see the results
The IDLE tool can also be used as a calculator. You can utilize
Step 2 : Next, enter the following code and save the file :
1 s = " H e l l o World ! "
2 print ( s )
Where :
1. We defined a variable named s with the value ’Hello World !’
2. We used the print() statement to display the value of the
variable s.
Step 3 : Running the code
Now, click on the icon shaped like a small green triangle loca-
You will then see the message ’Hello World !’ appear on the
console ! This is the value of the variable s displayed using the
print() statement.
Chapitre 2
Python Variable
A variable boils down to a name assigned to a value, al-
lowing Python to memorize it (not delete it) and retrieve
it later by its name. One can conceptualize the variable as a
kind of label affixed to our value, indicating how it is called. In
Python, assigning a value to a variable is done using the =
operator. On the left, :
1 myvariable = value
1. myvariable : here we specify the name of the variable, which
must be a sequence of characters without spaces.
2. value : here we specify the value of the variable, which can
take the form of any expression, as mentioned earlier.
19
CHAPITRE 2. DAY 2 : VARIABLES AND OPERATORS 20
2 print ( n )
3 # ou tp ut : 11
After execution this program displays 11. We can also display ex-
planatory text together with the variable n :
Exemple. display the variable with text :
1 n = 11
1 x = 13
2 y = 12.75
4 b = 10 < 3
2 print ( x ) # ou tp ut : 3
4 # change t h e t y p e o f x t o f l o a t
5 x = f l o a t ( x ) # x i s now o f t y p e f l o a t
6 print ( x ) # ou tp ut : 3 . 0