This article follows on from the first two parts that can be viewed here:
- https://128mots.com/index.php/2019/12/04/python-les-bases-capes-nsi-snt-en-plus-de-128-mots/
- https://128mots.com/index.php/2019/12/06/python-les-bases-en-plus-de-128-mots-partie-2/
I am discussing the basics of the Python language to learn it 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.
Tuples:
A tuple is an orderly collection like lists and immutable (that does not change).
exampleTuple ("apple," "pear," "strawberry") print (exampleTuple) print (exampleTupl[1]e) print (exampleTu[-1]ple) #L negative indexing means from the end, -1 refers to the last element, -2 refers to the penultimate element, etc. print (exampleTup[1:2]le) #Vous can specify an index range by specifying where to start and where to finish the range. z - list (exampleTuple) #conversion tuple on the list z[1] - "banana" x - tuple(z) #conversion tuple list for x in exampleTuple: #Boucle on a tuple print (x) if "pear" in exampleTuple: #test of existence in a tuple print ("Yes")
Unpacking:
coordinates - (1.2,3) x,y,z - coordinates print (x)
Dictionaries:
A dictionary is an unordered, editable and indexed collection.
Customer "name": "Elodie" "age": "45" "year": 1980 } print (custome["age"]r) custo["nouvelleCle"]mer - "new value" #ajoute a new key and value customer.get("solde") #renvoi 'None' because the key does not exist
Functions:
The features allow the code to be organized into reusable pieces. In Python, a function is defined using the keyword def.
def exemple_fonction(): print ("TestFunction") exemple_fonction()
The data can be switched to functions as a setting. You can add as many settings as you like, just separate them by a comma.
def exemple_fonction (first name): print ("Hello" - first name) exemple_fonction ("John") exemple_fonction ("Pierre")