Here are my notes to learn the python language very quickly. In France these bases are taught in high school at the second SNT, first and senior NSI classes. They are also part of the knowledge program for CAPES NSI.
- and: returnS True if both statements are true
- gold: Returns True if one of the statements is true
- Not: Reverse the result, return Sorset if the result is true
- Not equal
- >< Supérieur / Inférieur supérieur=""></ Supérieur / Inférieur>
- <=>Equal Lower /Equal Superior</=>
When the pass statement is executed, nothing happens, but you avoid an error when empty code is not allowed.
x - 22 y - 150 if x y: Pass
Using input statement:
name - input ("User name:") print ("Username is: "
The while loop executes a set of instructions as long as a condition is true. The break statement, allows to stop the loop even if the condition while is true.
x - 1 while x< 11:></ 11:> if x 5: Break x 1
A for loop performs an iteration on a sequence (a list, a tuple, a dictionary, a set or a string of character).
for x in[1, 2, 3]: print (x)
A chain of character:
for x in "hello": print (x)
tupleObjet ('Citroen', 2019, 'C4', 23000) for elements in tupleObj: print (elements)
dico - 'color': 'green', 'animal': 'dog', 'legume': 'spinach' for cle in dico: print
To complete a specific number of times, use the range function ().
for x in range(10): print (x)
A list is a collection that is ordered and editable and allows duplicates.
List["pomme", "banane", "poire"] print (list) print #A[-1]ffiche the last item on the list print #L[2:3]orsque you specify a range, the return value will be a new list with the specified items. print #Lorsque you specify a range, the return value will be a new list with the specified items. #En omitt[:3]ing the initial value, the range will start at the first element: print #En [1:]omitting the end value, the range will go to the end of the list: print #des[-2:-1] negative indexes to start the search from the end of the list: This example returns the elements of the index -2 (included) to the index -1 (excluded).