Python bases in more than 128 words[Partie 4]

This article follows on from the first three parts that can be viewed here:

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.


When an error occurs, (an exception) it can be managed using the try statement:

  print (r)
Except NameError:
  print ("undefined r variable")
  print ("Other exception") 


#Ceci is a comment
#plusieurs line
print ("Hello Python")
This is a comment
several line
print ("Hello Python")


Classes are like an object builder, it helps to model real concepts.

Person class:
  def __init__ (self, name, age):

  def ma_fonction (self):
    print ("Name of person: " '

p1 - Person ("Sebastian," 36)
print (
print (p1.age) 
p1.age - 40 #Modification of the properties of the object
del p1.age #supprime ownership of the object
del p1 #supprime the object

self is a reference to the current instance of the class and is used to access variables that belong to the class. It may be named other than self, but it must be the first setting of any class function.


Inheritance defines a class that inherits all the methods and properties of another class.

Animal class:
   def walk():
       print ('walk')

Class Dog (Animal)

c1 - Dog ()


The function __init () is automatically called every time a new object is created.

super () will make the child class inherit all the methods and properties of its parent.

Student class (Person):
  def __init__ (self, name, first name):
    super().__init__ (name, first name)