Professional Documents
Culture Documents
PYTHON
PACKAGING
• Python presentation
• Python notions recap
• Variables declarations
• Conditions
• Loops
• Functions
WHAT IS PYTHON ?
3
What is python ? Interpreted language.
Open source.
4
PYTHON USAGE
5
Python
Installation
At https://www.python.org/downloads/
6
VSCode installation
https://code.visualstudio.com/Download
7
PyCharm installation
https://www.jetbrains.com/pycharm/download/
8
BASIC PYTHON SYNTAX
9
Language syntax
11
SCALAR VARIABLES TYPES
Type What it is Examples
12
ARITHMETIC OPERATORS
13
Container types
Type Usage
list Stores a sequence of objects
tuple Immutable list
set Stores only one occurrence of an object
dict Stores objects by Associating keys to values
You can get the length / size of a container by using the len() function on it.
14
Container examples
# list creation, multiple object types inside are allowed
my_list = [0, 1, "hello"]
15
Container examples
# dict are used to associate keys to values
my_dict = {
"France": "Paris",
"Germany": "Berlin",
"Spain": "Madrid"
}
16
LIST METHODS
17
DICTIONARIES METHODS
Method Action
.clear() Empties the dictionary.
.keys() Returns all the keys.
.values() Returns all the values().
.items() Returns all the key/values couples in tuples.
.pop(key) Removes and returns the value at key.
.get(key, default) Returns the value linked to key or default if there is none.
18
CONDITION SYNTAX
if condition:
# Code to execute if condition is True
#
elif other_condition:
# Code to execute if other_condition is True
#
else:
# Code to execute if condition if False
#
19
COMPARISION OPERATORS
Operator Name Example
== Equal 1 == 1
!= Not equal 1 != 2
< Less than 1<2
> Greater than 2>1
<= Less than or equal 1<= 2
>= Greater than or equal 2 >= 2
20
LOGICAL OPERATORS
- Allows to create complex boolean logic.
21
Condition example
if x == 10:
print("x is 10")
elif x < 10:
print("x is less than 10")
else:
print("x is greater than 10")
22
LOOP ITERATIONS
23
FOR … IN ...
numbers = [1, 2, 4, 8, 16]
Used to iterate over an iterator. for i in numbers:
print(i)
24
FOR … IN RANGE(…)
25
FOR … IN RANGE(…)
# Show the squared values of the integers between 0 & 5
for i in range(0, 6):
squared = i ** 2
print(f"{i} * {i} = {squared}")
26
WHILE ...
i = 0
while i < 5:
Very useful for indefinite iteration print(f"{i=}")
i += 1
27
NESTED LOOPS
prefixes = ["I like", "I love"]
suffixes = ["apples", "chocolates"]
28
THE BREAK INSTRUCTION
The break instruction stops the execution of the parent loop.
stop_chars = "hk47-c3po"
phrase = "Hello there, general Kenobi !" >>> "H"
for char in phrase: >>> "e"
if char in stop_chars: >>> "l"
break >>> "l"
print(char)
29
THE CONTINUE INSTRUCTION
Skip the remaining instructions and go to the next iteration.
30
FUNCTION CREATION
31
FUNCTION CALL
• Functions are called using their name and a series of given
parameters :
32
FUNCTIONS EXAMPLES
33
DEFAULT PARAMETERS
• Parameters can have default values.
• You can mix parameters with a default value and no default value.
• Parameters with default values must be defined at the end.
def say_hello(name="world"):
print(f"Hello, {name} !")
34
Variables can have types
hints.
35
FUNCTION WITH TYPE HINT
user = "Bob"
banned: bool = is_user_banned(user)
36
Conclusion
• Python is an interpreted language.
• Variable can have dynamic types.
• Python uses indentation instead of brackets.
• The language has many common features of
programming languages.
• Functions are defined with the def keyword.
37
Let’s practice !
38