1. Preface:
Pen to forget words, feeling a lot! Python study back and forth for more than a year, it seems to spend a lot of time, actually did not learn anything, is in object-oriented programming before the basic knowledge this piece has been spinning, each time to the object-oriented this piece feels very blindfolded, see two days to give up, from the beginning again again. One day to learn a class derivation feel very good to go with the old programmer's classmates show off, the result people said a sentence, learned fast a year is still here ah, object-oriented understand? Socket programming will not, multithreading do not understand? I say... , people say don't keep wandering in this no meaning, first understand object-oriented in to hooves! I am a stubborn temper, but also be the person is not excited!
2. Process-oriented programming:
process-oriented : According to business logic from top to bottom write code, self-understanding is that you write where the program can be from the next step to the execution of where, where you can't write down, the program is in the implementation of the.
1 Print 'First day'2 Print'Get up'3 Print'Eat'4 Print'work'5 Print'off Duty'
print ' Home ' # # #新添加的功能6 Print'Sleep'7 #############################8 Print 'Next day'9 Print'Get up'Ten Print'Eat' One Print'work' A Print'off duty
print ' Home ' # # #新添加的功能
- Print'Sleep'
。。。。。
One months later, you have to write 30 of the same operation, if suddenly I want to add a "home" every day, then I need to modify 30 operations, is not very troublesome?
Process-oriented Programming drawbacks: rewrite every call, code is very long, code reusability does not, every time you add new features all the code is modified!
What is the solution to the above-mentioned drawbacks? The function will appear!!!
3. Functional programming
Function: Encapsulates a function code into a function, which is not required to be repeated at a later date, only functions can be called.
Functions can be understood as a function block, you split a large function into a piece, with a function of the time to call a function block can!
Functions can call functions! The function of the main function is to concatenate functions and invoke them! The function itself cannot be executed on its own if you don't call it and never do it!
1 defTest (Day):2 Print Day3 Print'Get up'4 Print'Eat'5 Print'work'6 Print'off Duty'
print ' Home ' # #新添加的功能. 7 Print'Sleep'8 9Test'First day')TenTest'Next day')
。。。。。
Also is the above process-oriented requirements, one months later, this time you only need to call 30 times the test (day) function can be, is not feeling a lot less code, if you want to add the "home" function, just add this function in the test () function, you do not need to modify something else.
Note: Functional programming, which loads the function address into memory when the code is first loaded.
Python "Fourth article": Object-oriented