Process-oriented programming is one of Python's two programming genres, and the other is object-oriented programming, a blog that only discusses process-oriented programming:
1. Concept
Process-oriented core is the process of the word, the process is to solve the problem of the steps, he is like the design of a factory assembly line, is a mechanical mode of thinking
2. Advantages
Complex problems are streamlined and simplified
3. Programming Example
User registration:
1 ImportJSON2 3 4 defInteractive ():5Name = input ('>>:'). Strip ()6PWD = input ('>>:'). Strip ()7 return {8 'name': Name,9 'pwd': pwdTen } One A - defCheck (user_info): -Is_valid =True the - ifLen (user_info['name']) ==0: - Print('user name cannot be empty') -Is_valid =False + - ifLen (user_info['pwd']) < 6: + Print('password must not be less than 6 bits') AIs_valid =False at - return { - 'Is_valid': Is_valid, - 'User_info': User_info - } - in - defRegister (check_info): to ifcheck_info['Is_valid']: +With open ('Db.json','W', encoding='Utf-8') as F: -Json.dump (check_info['User_info'], F) the * $ defMain ():Panax NotoginsengUser_info =Interactive () -Check_info =Check (user_info) the Register (Check_info) + A the if __name__=='__main__': +Main ()
Process decomposition, programming is simple, but later changes are complex, such as adding an option to fill in the email, the code is as follows:
1 ImportJSON2 ImportRe3 4 5 defInteractive ():6Name = input ('>>:'). Strip ()7PWD = input ('>>:'). Strip ()8email = input ('>>:'). Strip ()9 return {Ten 'name': Name, One 'pwd': pwd, A 'Email': Email - } - the - defCheck (user_info): -Is_valid =True - + ifLen (user_info['name']) ==0: - Print('user name cannot be empty') +Is_valid =False A at ifLen (user_info['pwd']) < 6: - Print('password must not be less than 6 bits') -Is_valid =False - - if notRe.search (R'@.*\.com$', user_info['Email']): - Print('Invalid mailbox Format') inIs_valid =False - to return { + 'Is_valid': Is_valid, - 'User_info': User_info the } * $ Panax Notoginseng defRegister (check_info): - ifcheck_info['Is_valid']: theWith open ('Db.json','W', encoding='Utf-8') as F: +Json.dump (check_info['User_info'], F) A the + defMain (): -User_info =Interactive () $Check_info =Check (user_info) $ Register (Check_info) - - the if __name__=='__main__': -Main ()
As can be seen from the above code, the process-oriented programming extensibility is poor, there is a reaching effect,
Usage scenarios: For projects where scalability requirements are not high
python--Process-oriented programming