Procedural programming paradigms
In Procedure Oriented programming paradigms, series of computational steps are divided modules which means that the code is grouped in functions and the code is serially executed step by step so basically, it combines the serial code to instruct a computer with each step to perform a certain task. This paradigm helps in the modularity of code and modularization is usually done by the functional implementation. This programming paradigm helps in an easy organization related items without difficulty and so each file acts as a container.
Advantages
- General-purpose programming
- Code reusability
- Portable source code
Disadvantages
- Data protection
- Not suitable for real-world objects
- Harder to write
Example:
# Procedural way of finding sum # of a list mylist = [ 10 , 20 , 30 , 40 ] # modularization is done by # functional approach def sum_the_list(mylist): res = 0 for val in mylist: res + = val return res print (sum_the_list(mylist)) |
Output:
100
Programming Paradigms in Python
Paradigm can also be termed as a method to solve some problems or do some tasks. A programming paradigm is an approach to solve the problem using some programming language or also we can say it is a method to solve a problem using tools and techniques that are available to us following some approach. There are lots of programming languages that are known but all of them need to follow some strategy when they are implemented and this methodology/strategy is paradigms. Apart from varieties of programming languages, there are lots of paradigms to fulfill each and every demand.
Python supports three types of Programming paradigms
- Object Oriented programming paradigms
- Procedure Oriented programming paradigms
- Functional programming paradigms