Python basics and python Basics
- Variables and assignments
- Name = 'kevin ': if the value of a variable is of the str type, it must be caused ''.
- Age = 21: ''is not required if it is an int''
- Variables and names
- Easy to understand: it is best to be knowledgeable
- Nums_of_kevin_gf = 10
- NumsOfKevinGf = 20: hump method
- Name-of-kevin-gf = 10: the non-standard naming method triggers a syntax error. python interprets '-' As 'subtract'
- 5 name = 2: The digit cannot start with na4me (available)
- ! Name = 4: special characters cannot be like! @~ & %...
- Name of to = 5: No space is allowed between variable names
- Dictionary Operation Method
- Append (): append
- Count (): Statistics
- Extend (): Extended
- Index (): index
- Insert (): insert
- Pop (): delete
- Remove (): Delete
- Reverse (): reverse
- Sort (): sort
- Operator
- &: Operator
- |: OR operator
- ^: OR operator
- ~ : Anti-Operator
- <: Left-move Operator
- >>: Right-moving Operator
- Logical operators
- And: Boolean "and". True is returned only when both are True.
- Or: Boolean "or". If one is True, True is returned.
- Not; Boolean "not". If X is True, False is returned. If X is False, True is returned.
- Member Operators
- In: If the returned value is "found", True is returned; otherwise, False is returned.
- Not in: If no value is found in the specified return, True is returned; otherwise, False is returned.
- Identity Operators
- Is: if the returned property is the same as the specified property, True is returned; otherwise, False is returned.
- Not is: if the returned property is different from the specified property, True is returned; otherwise, False is returned.
- Nested loop
- Break: jump out of this loop
- Continue: jump out of this loop and start the next loop
- While Loop
- For Loop
- If... else judgment
- File Operations
- Name_file = open ('xxx', 'w'): the first parameter for opening a file is file path + file name, and the second parameter is open mode.
- W: Write mode
- R: Read mode
- A: append Mode
- Name_file.write ('sss'): Add, must be in writable or append Mode
- Name_file.read (): reads a file, which must be in readable mode.
- Name_file.readline (): Read row by row
- Name_file.readlines (): Read all rows
- Name_file.close (): Close the file
Assignments for week 1:
Job: Write the login interface
- Enter user name and password
- Welcome information displayed after successful authentication
- Lock after three wrong attempts
1 #-*-coding: UTF-8-*-2 # Author: xiaorui 3 # Save the user and password in dictionary format 4 user_name = {"huofucheng": "123456aa", "wangkai ": "123456bb", "cangjingkong": "123456cc", "wutenglan": "123456dd"} 5 lock_name_file = open('lockname.txt ', "r +") 6 lock_name = encrypt () 7 name = input ("Enter the User name:") 8 if name in lock_name: 9 print ("your account has been locked! ") 10 else: 11 if name in user_name: 12 x = 013 while x <3:14 passworld = input (" Enter Password: ") 15 if passworld = user_name [name]: 16 # print ("Welcome! ", Name) 18 break19 else: 20 print (" Incorrect password. Please try again! ") 21 x = x + 122 else: 23 # enter an error three times to stop 24 lock_name_file.write (name) 25 lock_name_file.close () 26 print (" three wrong password input! Your account has been locked! ") 27 else: 28 print (" the user does not exist! Please register! ")View Code