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.
Logic operators:
- 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
Comparison operators:
- Equality
- Not equal
- >< Supérieur / Inférieur supérieur=""></ Supérieur / Inférieur>
- <=>Equal Lower /Equal Superior</=>
- Different!
Keyword pass:
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
User entry:
Using input statement:
name - input ("User name:") print ("Username is: "
While Loop:
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
For Loop:
A for loop performs an iteration on a sequence (a list, a tuple, a dictionary, a set or a string of character).
A list:
for x in[1, 2, 3]: print (x)
A chain of character:
for x in "hello": print (x)
A tuple:
tupleObjet ('Citroen', 2019, 'C4', 23000) for elements in tupleObj: print (elements)
A dictionary:
dico - 'color': 'green', 'animal': 'dog', 'legume': 'spinach' for cle in dico: print
Range function:
To complete a specific number of times, use the range function ().
for x in range(10): print (x)
Lists:
A list is a collection that is ordered and editable and allows duplicates.
List["pomme", "banane", "poire"] print (list[1]) 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).