Built-in functions
bytes () decodes characters
chr () / ord () chr () refer to a digital ASCII code table converted into a corresponding character; the ord () converts characters into a corresponding digital
divmod () columns
enumerate () iteration with indexes
eval () translates into a string data type
hash () whether the hash
- ABS () absolute value
- all () within iterables elements are all true, then returns true
- any () iterables there is an element is true, True
- bin () / oct () / hex () binary, octal, hexadecimal conversion
- dir () functions include all the time
- frozenset () set immutable
- globals () / loacals () to check the global names; see local name
- POW () introduced into the module string
- round()
- slice()
- sum()
- import()
Process-oriented programming
Pros: complex processes of the problem, and then simplify
Disadvantages: poor scalability
Registration function
Accept user input a user name, validity check, get a legitimate user name
def check_username(): username=input('username:').strip() if username.isalpha(): return username else: print('必须为字母')
Enter the password, the legality verification, to get a legitimate password
def check_pwd(): while True: pwd = input('password>>>').strip() if len(pwd) < 5: print('密码长度至少五位') continue re_pwd = input('re_password>>>').strip() if pwd == re_pwd: return pwd else: print('两次输入密码不一致')
The valid user name and password are written to the file
def insert(username, pwd, path='57.txt'): with open(path, 'a', encoding='utf8') as fa: fa.write(f'{username}:{pwd}\n')
registered
def register(): username = check_username() pwd = check_pwd() insert(username, pwd) print(f'{username}注册成功') register()
Stratified realize the function
- User functional layers: User specific functions implemented.
- Interface Layer: connecting the user and the data processing layer functional layer.
- Layer Data Processing: The data processing results to the Interface Layer.
Realize the benefits of layered function: When the end we need to implement web and app software side, we just put data processing layer and the interface layer written, then realize different functional layers to the user, web-side end users using a web functional layer, app end end user using the app functional layer, but the interface layer and the data processing layer are common.