Python
Python
Variables
Python
Variables
age = 42
user_name = "johndoe"
_do_not_use = "secret"
__very_important = "notreally"Python
Variables
age = 42
user_name = "johndoe"
_do_not_use = "secret"
__very_important = "notreally"Python
Variables
age = 42
user_name = "johndoe"
_do_not_use = "secret"
__very_important = "notreally"Python
Variables
age = 42
user_name = "johndoe"
_do_not_use = "secret"
__very_important = "notreally"Python
Variables
age = 42
user_name = "johndoe"
_do_not_use = "secret"
__very_important = "notreally"Python
Types
Python
Types
age = 42
username = "johndoe"
lucky_numbers = [42, 777, 12345]
kara = ("Cat", 2003, "Benghal")
translations = {
"hello": "bonjour",
"bye": "au revoir"
}Python
Types
age = 42
username = "johndoe"
lucky_numbers = [42, 777, 12345]
kara = ("Cat", 2003, "Benghal")
translations = {
"hello": "bonjour",
"bye": "au revoir"
}Python
Types
age = 42
username = "johndoe"
lucky_numbers = [42, 777, 12345]
kara = ("Cat", 2003, "Benghal")
translations = {
"hello": "bonjour",
"bye": "au revoir"
}Python
Types
age = 42
username = "johndoe"
lucky_numbers = [42, 777, 12345]
kara = ("Cat", 2003, "Benghal")
translations = {
"hello": "bonjour",
"bye": "au revoir"
}Python
Types
age = 42
username = "johndoe"
lucky_numbers = [42, 777, 12345]
kara = ("Cat", 2003, "Benghal")
translations = {
"hello": "bonjour",
"bye": "au revoir"
}Python
Types
age = 42
username = "johndoe"
lucky_numbers = [42, 777, 12345]
kara = ("Cat", 2003, "Benghal")
translations = {
"hello": "bonjour",
"bye": "au revoir"
}Python
Opérateurs artihmétiques
Python
Opérateurs artihmétiques
addition = 1 + 2
subtraction = 1 - 2
multiplication = 1 * 2
division = 1 / 2
floor_division = 1 // 2
exponentiation = 2 ** 4
modulus = 4 % 2Python
Opérateurs artihmétiques
addition = 1 + 2
subtraction = 1 - 2
multiplication = 1 * 2
division = 1 / 2
floor_division = 1 // 2
exponentiation = 2 ** 4
modulus = 4 % 2Python
Opérateurs artihmétiques
addition = 1 + 2
subtraction = 1 - 2
multiplication = 1 * 2
division = 1 / 2
floor_division = 1 // 2
exponentiation = 2 ** 4
modulus = 4 % 2Python
Opérateurs artihmétiques
addition = 1 + 2
subtraction = 1 - 2
multiplication = 1 * 2
division = 1 / 2
floor_division = 1 // 2
exponentiation = 2 ** 4
modulus = 4 % 2Python
Opérateurs artihmétiques
addition = 1 + 2
subtraction = 1 - 2
multiplication = 1 * 2
division = 1 / 2
floor_division = 1 // 2
exponentiation = 2 ** 4
modulus = 4 % 2Python
Opérateurs artihmétiques
addition = 1 + 2
subtraction = 1 - 2
multiplication = 1 * 2
division = 1 / 2
floor_division = 1 // 2
exponentiation = 2 ** 4
modulus = 4 % 2Python
Opérateurs artihmétiques
addition = 1 + 2
subtraction = 1 - 2
multiplication = 1 * 2
division = 1 / 2
floor_division = 1 // 2
exponentiation = 2 ** 4
modulus = 4 % 2Python
Opérateurs artihmétiques
addition = 1 + 2
subtraction = 1 - 2
multiplication = 1 * 2
division = 1 / 2
floor_division = 1 // 2
exponentiation = 2 ** 4
modulus = 4 % 2Python
Opérateurs d'affectation
Python
Opérateurs d'affectation
assignment = 5
addition_assignment += 3
subtraction_assignment -= 8
multiplication_assignment *= 4
division_assignment /= 2
modulus_assignment %= 6
floor_division_assignment //= 5
exponentiation_assignment **= 3Python
Opérateurs d'affectation
assignment = 5
addition_assignment += 3
subtraction_assignment -= 8
multiplication_assignment *= 4
division_assignment /= 2
modulus_assignment %= 6
floor_division_assignment //= 5
exponentiation_assignment **= 3Python
Opérateurs d'affectation
assignment = 5
addition_assignment += 3
subtraction_assignment -= 8
multiplication_assignment *= 4
division_assignment /= 2
modulus_assignment %= 6
floor_division_assignment //= 5
exponentiation_assignment **= 3Python
Opérateurs d'affectation
assignment = 5
addition_assignment += 3
subtraction_assignment -= 8
multiplication_assignment *= 4
division_assignment /= 2
modulus_assignment %= 6
floor_division_assignment //= 5
exponentiation_assignment **= 3Python
Opérateurs d'affectation
assignment = 5
addition_assignment += 3
subtraction_assignment -= 8
multiplication_assignment *= 4
division_assignment /= 2
modulus_assignment %= 6
floor_division_assignment //= 5
exponentiation_assignment **= 3Python
Opérateurs d'affectation
assignment = 5
addition_assignment += 3
subtraction_assignment -= 8
multiplication_assignment *= 4
division_assignment /= 2
modulus_assignment %= 6
floor_division_assignment //= 5
exponentiation_assignment **= 3Python
Opérateurs d'affectation
assignment = 5
addition_assignment += 3
subtraction_assignment -= 8
multiplication_assignment *= 4
division_assignment /= 2
modulus_assignment %= 6
floor_division_assignment //= 5
exponentiation_assignment **= 3Python
Opérateurs d'affectation
assignment = 5
addition_assignment += 3
subtraction_assignment -= 8
multiplication_assignment *= 4
division_assignment /= 2
modulus_assignment %= 6
floor_division_assignment //= 5
exponentiation_assignment **= 3Python
Opérateurs d'affectation
assignment = 5
addition_assignment += 3
subtraction_assignment -= 8
multiplication_assignment *= 4
division_assignment /= 2
modulus_assignment %= 6
floor_division_assignment //= 5
exponentiation_assignment **= 3Python
Opérateurs de comparaison
Python
Opérateurs de comparaison
"amin" == 123
"javascript" != "python"
"love" > "hate"
42 < 24
index >= limit
radians <= 3.14Python
Opérateurs de comparaison
"amin" == 123
"javascript" != "python"
"love" > "hate"
42 < 24
index >= limit
radians <= 3.14Python
Opérateurs de comparaison
"amin" == 123
"javascript" != "python"
"love" > "hate"
42 < 24
index >= limit
radians <= 3.14Python
Opérateurs de comparaison
"amin" == 123
"javascript" != "python"
"love" > "hate"
42 < 24
index >= limit
radians <= 3.14Python
Opérateurs de comparaison
"amin" == 123
"javascript" != "python"
"love" > "hate"
42 < 24
index >= limit
radians <= 3.14Python
Opérateurs de comparaison
"amin" == 123
"javascript" != "python"
"love" > "hate"
42 < 24
index >= limit
radians <= 3.14Python
Opérateurs de comparaison
"amin" == 123
"javascript" != "python"
"love" > "hate"
42 < 24
index >= limit
radians <= 3.14Python
Opérateurs de logique
Python
Opérateurs de logique
user == "admin" and level > 42
animal == "cat" or animal == "dog"
not paid_user
data is int
database_connection is not NonePython
Opérateurs de logique
user == "admin" and level > 42
animal == "cat" or animal == "dog"
not paid_user
data is int
database_connection is not NonePython
Opérateurs de logique
user == "admin" and level > 42
animal == "cat" or animal == "dog"
not paid_user
data is int
database_connection is not NonePython
Opérateurs de logique
user == "admin" and level > 42
animal == "cat" or animal == "dog"
not paid_user
data is int
database_connection is not NonePython
Opérateurs de logique
user == "admin" and level > 42
animal == "cat" or animal == "dog"
not paid_user
data is int
database_connection is not NonePython
Opérateurs de logique
user == "admin" and level > 42
animal == "cat" or animal == "dog"
not paid_user
data is int
database_connection is not NonePython
Opérateurs d'appartenance
Python
Opérateurs d'appartenance
user_role in ["ADMIN", "SUPERADMIN", "USER"]
email not in ["admin@42.fr", "super@404placevendome.com"]Python
Opérateurs d'appartenance
user_role in ["ADMIN", "SUPERADMIN", "USER"]
email not in ["admin@42.fr", "super@404placevendome.com"]Python
Opérateurs d'appartenance
user_role in ["ADMIN", "SUPERADMIN", "USER"]
email not in ["admin@42.fr", "super@404placevendome.com"]Python
Structures conditionnelles
Python
Structures conditionnelles
if twitch_command == "!level":
print("Level 60")
elif twitch_command == "!class":
print("War Arm")
elif twitch_command == "!pvp":
print("1k2 (with Holy Paladin)")
else:
print("Unrecognized command")Python
Structures conditionnelles
if twitch_command == "!level":
print("Level 60")
elif twitch_command == "!class":
print("War Arm")
elif twitch_command == "!pvp":
print("1k2 (with Holy Paladin)")
else:
print("Unrecognized command")Python
Structures conditionnelles
if twitch_command == "!level":
print("Level 60")
elif twitch_command == "!class":
print("War Arm")
elif twitch_command == "!pvp":
print("1k2 (with Holy Paladin)")
else:
print("Unrecognized command")Python
Structures conditionnelles
if twitch_command == "!level":
print("Level 60")
elif twitch_command == "!class":
print("War Arm")
elif twitch_command == "!pvp":
print("1k2 (with Holy Paladin)")
else:
print("Unrecognized command")Python
Structures conditionnelles raccourcies
Python
Structures conditionnelles raccourcies
if age > 18: print("You can drive")
print("Connected") if is_valid_password else print("Login")Python
Structures conditionnelles raccourcies
if age > 18: print("You can drive")
print("Connected") if is_valid_password else print("Login")Python
Structures conditionnelles raccourcies
if age > 18: print("You can drive")
print("Connected") if is_valid_password else print("Login")Python
Boucle while
Python
Boucle while
counter = 0
while counter < 10:
print(counter)
counter += 1
else:
print("End of the loop")Python
Boucle while
counter = 0
while counter < 10:
print(counter)
counter += 1
else:
print("End of the loop")Python
Boucle while
counter = 0
while counter < 10:
print(counter)
counter += 1
else:
print("End of the loop")Python
Boucle while
counter = 0
while counter < 10:
print(counter)
counter += 1
else:
print("End of the loop")Python
Boucle while
counter = 0
while counter < 10:
print(counter)
counter += 1
else:
print("End of the loop")Python
Break, continue
Python
Break, continue
number = 0
while True:
number += 1
if number > 99:
break
if number % 5 == 0:
continue
print(number)Python
Break, continue
number = 0
while True:
number += 1
if number > 99:
break
if number % 5 == 0:
continue
print(number)Python
Break, continue
number = 0
while True:
number += 1
if number > 99:
break
if number % 5 == 0:
continue
print(number)Python
Break, continue
number = 0
while True:
number += 1
if number > 99:
break
if number % 5 == 0:
continue
print(number)Python
Break, continue
number = 0
while True:
number += 1
if number > 99:
break
if number % 5 == 0:
continue
print(number)Python
Break, continue
number = 0
while True:
number += 1
if number > 99:
break
if number % 5 == 0:
continue
print(number)Python
Break, continue
number = 0
while True:
number += 1
if number > 99:
break
if number % 5 == 0:
continue
print(number)Python
Boucle for
Python
Boucle for
fruits = [
"banana",
"strawberry",
"lemon",
"orange",
"ananas"
]
for fruit in fruits:
if fruit == "strawberry":
continue
if fruit == "orange":
break
print(fruit)
else:
print("Finished printing fruits")
Python
Boucle for
fruits = [
"banana",
"strawberry",
"lemon",
"orange",
"ananas"
]
for fruit in fruits:
if fruit == "strawberry":
continue
if fruit == "orange":
break
print(fruit)
else:
print("Finished printing fruits")
Python
Boucle for
fruits = [
"banana",
"strawberry",
"lemon",
"orange",
"ananas"
]
for fruit in fruits:
if fruit == "strawberry":
continue
if fruit == "orange":
break
print(fruit)
else:
print("Finished printing fruits")
Python
Boucle for
fruits = [
"banana",
"strawberry",
"lemon",
"orange",
"ananas"
]
for fruit in fruits:
if fruit == "strawberry":
continue
if fruit == "orange":
break
print(fruit)
else:
print("Finished printing fruits")
Python
Boucle for
fruits = [
"banana",
"strawberry",
"lemon",
"orange",
"ananas"
]
for fruit in fruits:
if fruit == "strawberry":
continue
if fruit == "orange":
break
print(fruit)
else:
print("Finished printing fruits")
Python
Boucle for
fruits = [
"banana",
"strawberry",
"lemon",
"orange",
"ananas"
]
for fruit in fruits:
if fruit == "strawberry":
continue
if fruit == "orange":
break
print(fruit)
else:
print("Finished printing fruits")
Python
Boucle for
fruits = [
"banana",
"strawberry",
"lemon",
"orange",
"ananas"
]
for fruit in fruits:
if fruit == "strawberry":
continue
if fruit == "orange":
break
print(fruit)
else:
print("Finished printing fruits")
Python
Fonctions
Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Fonctions
def print_hello():
print("Hello")
print_hello()
def print_addition_three(first, second, third):
print(first + second + third)
print_addition_three(1, 2, 3)
def print_greetings(name = "world"):
print("Hello " + name + "!")
print_greetings()
print_greetings("John")
def greetings(name = "world"):
return "Hello " + name + "!"
print(greetings())
print(greetings("John"))Python
Paramètres nommés
Python
Paramètres nommés
def divide(numerator, denominator):
if denominator == 0:
return 0
return numerator / denominator
print(divide(8, 4));
print(divide(numerator = 8, denominator = 4));
print(divide(denominator = 4, numerator = 8));Python
Paramètres nommés
def divide(numerator, denominator):
if denominator == 0:
return 0
return numerator / denominator
print(divide(8, 4));
print(divide(numerator = 8, denominator = 4));
print(divide(denominator = 4, numerator = 8));Python
Paramètres nommés
def divide(numerator, denominator):
if denominator == 0:
return 0
return numerator / denominator
print(divide(8, 4));
print(divide(numerator = 8, denominator = 4));
print(divide(denominator = 4, numerator = 8));Python
Paramètres nommés
def divide(numerator, denominator):
if denominator == 0:
return 0
return numerator / denominator
print(divide(8, 4));
print(divide(numerator = 8, denominator = 4));
print(divide(denominator = 4, numerator = 8));Python
Paramètres nommés
def divide(numerator, denominator):
if denominator == 0:
return 0
return numerator / denominator
print(divide(8, 4));
print(divide(numerator = 8, denominator = 4));
print(divide(denominator = 4, numerator = 8));Python
Paramètres arbitraires
Python
Paramètres arbitraires
def sum(*numbers):
sum = 0
for number in numbers:
sum += number
return sum
print(sum(1, 2))
print(sum(1, 2, 3))
print(sum(1, 2, 3, 4))
print(sum(1, 2, 3, 4, 5))Python
Paramètres arbitraires
def sum(*numbers):
sum = 0
for number in numbers:
sum += number
return sum
print(sum(1, 2))
print(sum(1, 2, 3))
print(sum(1, 2, 3, 4))
print(sum(1, 2, 3, 4, 5))Python
Paramètres arbitraires
def sum(*numbers):
sum = 0
for number in numbers:
sum += number
return sum
print(sum(1, 2))
print(sum(1, 2, 3))
print(sum(1, 2, 3, 4))
print(sum(1, 2, 3, 4, 5))Python
Paramètres arbitraires
def sum(*numbers):
sum = 0
for number in numbers:
sum += number
return sum
print(sum(1, 2))
print(sum(1, 2, 3))
print(sum(1, 2, 3, 4))
print(sum(1, 2, 3, 4, 5))Python
Paramètres arbitraires
def sum(*numbers):
sum = 0
for number in numbers:
sum += number
return sum
print(sum(1, 2))
print(sum(1, 2, 3))
print(sum(1, 2, 3, 4))
print(sum(1, 2, 3, 4, 5))Python
Paramètres arbitraires
def sum(*numbers):
sum = 0
for number in numbers:
sum += number
return sum
print(sum(1, 2))
print(sum(1, 2, 3))
print(sum(1, 2, 3, 4))
print(sum(1, 2, 3, 4, 5))Python
Paramètres arbitraires
def sum(*numbers):
sum = 0
for number in numbers:
sum += number
return sum
print(sum(1, 2))
print(sum(1, 2, 3))
print(sum(1, 2, 3, 4))
print(sum(1, 2, 3, 4, 5))Python
Paramètres arbitraires nommés
Python
Paramètres arbitraires nommés
def print_names(**parameters):
if "first_name" in parameters:
print("First name is " + parameters["first_name"])
if "last_name" in parameters:
print("Last name is " + parameters["last_name"])
print_names(email = "johndoe@domain.com")
print_names(first_name = "John")
print_names(last_name = "DOE")
print_names(first_name = "John", last_name = "DOE")Python
Paramètres arbitraires nommés
def print_names(**parameters):
if "first_name" in parameters:
print("First name is " + parameters["first_name"])
if "last_name" in parameters:
print("Last name is " + parameters["last_name"])
print_names(email = "johndoe@domain.com")
print_names(first_name = "John")
print_names(last_name = "DOE")
print_names(first_name = "John", last_name = "DOE")Python
Paramètres arbitraires nommés
def print_names(**parameters):
if "first_name" in parameters:
print("First name is " + parameters["first_name"])
if "last_name" in parameters:
print("Last name is " + parameters["last_name"])
print_names(email = "johndoe@domain.com")
print_names(first_name = "John")
print_names(last_name = "DOE")
print_names(first_name = "John", last_name = "DOE")Python
Paramètres arbitraires nommés
def print_names(**parameters):
if "first_name" in parameters:
print("First name is " + parameters["first_name"])
if "last_name" in parameters:
print("Last name is " + parameters["last_name"])
print_names(email = "johndoe@domain.com")
print_names(first_name = "John")
print_names(last_name = "DOE")
print_names(first_name = "John", last_name = "DOE")Python
Paramètres arbitraires nommés
def print_names(**parameters):
if "first_name" in parameters:
print("First name is " + parameters["first_name"])
if "last_name" in parameters:
print("Last name is " + parameters["last_name"])
print_names(email = "johndoe@domain.com")
print_names(first_name = "John")
print_names(last_name = "DOE")
print_names(first_name = "John", last_name = "DOE")Python
Paramètres arbitraires nommés
def print_names(**parameters):
if "first_name" in parameters:
print("First name is " + parameters["first_name"])
if "last_name" in parameters:
print("Last name is " + parameters["last_name"])
print_names(email = "johndoe@domain.com")
print_names(first_name = "John")
print_names(last_name = "DOE")
print_names(first_name = "John", last_name = "DOE")Python
Paramètres arbitraires nommés
def print_names(**parameters):
if "first_name" in parameters:
print("First name is " + parameters["first_name"])
if "last_name" in parameters:
print("Last name is " + parameters["last_name"])
print_names(email = "johndoe@domain.com")
print_names(first_name = "John")
print_names(last_name = "DOE")
print_names(first_name = "John", last_name = "DOE")Python
By Amin Nairi
Python
- 91