Python: What to learn and How much?
source link: https://towardsdatascience.com/python-what-to-learn-and-how-much-fb61bdef7b3a
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Python: What to learn and How much?
Imperative, Functional, Object-Oriented: Which programming paradigm is a good fit for my job?
Python programming is like endless possibilities. Web and Internet Development, Desktop GUI based application, Machine Learning, Deep Learning, Software Development, Business Applications development there is a big list of use cases of Python programming. Considering so much is there to learn, it’s easy to get lost and wonder how-much-is-too-much.
In this article, I will take you through different programming paradigms Python supports and help you decide which one you should learn first.
Programming Paradigm is a style or way to classify programming languages.
Python support three programming paradigms: Imperative, Functional, and Object-Oriented. Figure 1, shows features of each of these programming paradigms.
Imperative
Imperative programming provides explicit steps to the computer using statements, loops, etc.
Below is an example of imperative programming. This is a simple instruction to the computer, how to concatenate characters provided in a list, and make a string.
If you run the above statements and loop it will print
sanrusha
In imperative programming set of commands can be grouped in a code block also called Procedure.
Statements and loop in the above code can be grouped in a Procedure (Python method) like below.
Now, the method stringc can be called with a list of characters as an argument.
stringc([‘s’,’a’,’n’,’r’,’u’,’s’,’h’,’a’])
The above call will return
sanrusha
Now, the approach is modularized than before. While the procedure makes imperative programming modularized, state changes are either localized to a procedure or limited to the explicit argument or return from the procedure.
Functional
The functional programming paradigm is a style of programming that involves using built-in higher-order functions. A higher-order function takes other function as an argument or returns them as a result.
Python built-in functions like lambda, map, filter, generators, decorators, recursions are higher-order functions. As long as you know what you want, you can use the best-fit built-in python function to accomplish it in the lowest number of lines of code.
The below code shows how to accomplish the same of combining characters into string in less than three lines of codes, by using Python higher-order functions like reduce and lambda.
Refer below link to get a complete list of built-in higher-order functions available in Python
Object-Oriented
An object-oriented programming (OOP) paradigm is so famous that you have to put your best effort into ignorance to not know about it. One of the reasons, object-oriented programming became so famous is it makes the code reusable. This is like taking the blueprint of a building and constructing the building with your own preferences like the number of floors, color, flooring, etc.
The blueprint in the case of OOP is called class. You are free to instantiate the class into an object with your own preferences. While you can not make a bike with a blueprint of a car, you can decide a lot of variations in the car while using the blueprint.
Python is full of built-in classes that you will use in your programs. While it is not easy to master OOP from day one, the good news is that you might not need to write an OOP program from scratch from day one in your job. For a few jobs, you might never need to write an OOP and your job might suffice by using built-in classes.
Below is an example of, how to accomplish the same task of creating a string out of characters with OOP.
Where to start?
Now comes the question you have.
Where to start?
The answer depends on the job you are going to perform. Figure 6 shows the python programming paradigm you should focus on based on your job.
Conclusion
If you don’t know anything about programming and have a little idea of Python, start with an imperative paradigm and get knowledge of Functional programming. Knowledge of built-in higher-order python functions will help you a lot. Once you are comfortable with these paradigms, start exploring object-oriented programming.
References:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK