Functions and Modules – Reuse of the Code
In the first two parts of the course we saw some simple steps to write code in Python. The codes were very simple and short, but in reality the codes reach many lines and then writing the code and making coding as efficient as possible is an activity that always requires further refinements.
One of these is the possibility of being able to reuse the code where and when possible.
DRY principle – Do not Repeat Yourself. It is one of the principles to keep in mind for all programmers.
WET principle – Write Everything Twice. It is said when a code turns out to be repetitive.
Often in the preparation of a program the same sequence of operations must be used several times during the execution of a script or a program. It exists not only in Python, but in most programming languages using both functions and modules for this purpose.
Writing a short code full of functions, without repetitions, makes it much more readable, short and therefore easy to maintain.
⇐ Go to Python Lesson 2.11 – FOR Loop
Go to Python Lesson 3.2 – Functions ⇒