Learn&Go est une entreprise développant des logiciels visant à favoriser l'apprentissage par le numérique et aider les enseignants. Go (or Golang) is an open source programming language designed to build fast, reliable, and efficient software at scale. All methods take "self" as the first argument'yo... yo... microphone check... one two... one two...'# They are called with the calling class as the first argument# A static method is called without a class or instance reference# It turns the method age() into an read-only attribute of the same name.# There's no need to write trivial getters and setters in Python, though.# When a Python interpreter reads a source file it executes all its code.# This __name__ check makes sure this code block is only executed when this# i and j are instances of type Human, or in other words: they are Human objects# Cannot call static method with instance of object# because i.grunt() will automatically put "self" (the object i) as an argument# => TypeError: grunt() takes 0 positional arguments but 1 was given# i.age # => this would raise an AttributeError######################################################################################################### Inheritance allows new child classes to be defined that inherit methods and# Using the Human class defined above as the base or parent class, we can# define a child class, Superhero, which inherits the class variables like# "species", "name", and "age", as well as methods, like "sing" and "grunt"# from the Human class, but can also have its own unique properties.# To take advantage of modularization by file you could place the classes above in their own files,# To import functions from other files use the following format# from "filename-without-extension" import "function-or-class"# Specify the parent class(es) as parameters to the class definition# If the child class should inherit all of the parent's definitions without# any modifications, you can just use the "pass" keyword (and nothing else)# but in this case it is commented out to allow for a unique child class:# Child classes can override their parents' attributes# Children automatically inherit their parent class's constructor including# its arguments, but can also define additional arguments or definitions# and override its methods such as the class constructor.# This constructor inherits the "name" argument from the "Human" class and# be aware of mutable default values, since defaults are shared# The "super" function lets you access the parent class's methods# that are overridden by the child, in this case, the __init__ method.# Get the Method Resolution search Order used by both getattr() and super()# Calls parent method but uses its own class attribute######################################################################################################### And yet another class definition that inherits from Superhero and Bat# Define Batman as a child that inherits from both Superhero and Bat# Typically to inherit attributes you have to call super:# super(Batman, self).__init__(*args, **kwargs) # However we are dealing with multiple inheritance here, and super()# only works with the next base class in the MRO list.# So instead we explicitly call __init__ for all ancestors.# The use of *args and **kwargs allows for a clean way to pass arguments,# Get the Method Resolution search Order used by both getattr() and super().# Calls parent method but uses its own class attribute# Calls method from Human, because inheritance order matters# Inherited attribute from 2nd ancestor whose default value was overridden.######################################################################################################### Generators are memory-efficient because they only load the data needed to# process the next value in the iterable.