Day1 Python Notes

Source: Internet
Author: User
Tags logical operators

Day1
  • Variables and Assignments
    • name = ' Kevin ': If the variable is assigned a STR type requires ' ' cause
    • Age = 21: If an int does not need '
  • variable and named
    • Easy to understand: It's best to be able to see the name and know it
    • NUMS_OF_KEVIN_GF = ten
    • NUMSOFKEVINGF = 20: Hump method
    • NAME-OF-KEVIN-GF = 10: Nonstandard naming method, triggering syntax error, Python interprets '-' as ' subtraction '
    • 5name = 2: Number cannot start, na4me (can be used)
    • !name = 4: Special characters cannot resemble [email protected]~&% ...
    • name of To = 5: cannot have spaces between variable names
  • Dictionary operation method
    • append (): Append
    • count (): Statistics
    • extend (): Extended
    • index (): Index
    • insert (): Insert
    • pop (): Delete a
    • remove (): Specify delete
    • reverse (): Invert
    • sort (): Sort
  • Operator
    • &: with operator
    • |: Or operator
    • ^: also or operator
    • ~: Take the inverse operator
    • <<: Left move operator
    • >>: Right Move operator
  • logical operators
    • And: Boolean "and", only true at the same time, returns True
    • Or: Boolean "or", which returns True if one is true
    • Not; Boolean "non", returns False if X is true, or True if X is False
  • Member operators
    • In: Returns True if the value returned as found in the specified returns false otherwise
    • Not in: Returns True if no value is found within the specified return, otherwise false
  • Identity operator
    • is: Returns True if the Returned property is the same as the specified property, otherwise returns false
    • Not is: Returns True if the returned property is different from the specified property, otherwise returns false
  • Nested loops
    • Break: Jump out of this layer of loops
    • Continue: Jump out of this cycle to start the next cycle
  • File operations
    • Name_file = open (' xxx ', ' W '): Opens the file The first parameter is the file path + filename, the second argument is open mode
      • W: Write mode
      • R: Read mode
      • A: Append mode
    • Name_file.write (' ssss '): added, must be in writable mode or Append mode
    • Name_file.read (): Read file, must be in readable mode
    • Name_file.readline (): progressive read
    • Name_file.readlines (): Read all Rows
    • Name_file.close (): Close file
  • Day1 Job
    • Jobs: Writing Login Interfaces
      • Enter User name password
      • Show welcome message after successful authentication
      • Lock after entering three times
    • 1 ImportSYS2 3locking = ('Login/locking.txt')4Login = ('Login/login.txt')5 6 defMain ():7Count_min =08Count_max = 39 Ten      whileCount_min <Count_max: OneUsername = input ("Please enter user name:")#Guide user to enter user name AWith open (locking,'R') as Locking_file:#open files that record locked users -              forLineinchlocking_file.readlines (): -                 ifUsername = = Line.strip ('\ n'):#determine if the user is in a locked user file theSys.exit ('%s user has been locked ... '%username) -  -Password = input ("Please enter user password:")#Guide user to enter password -With open (login,'R') as Login_file: +              forLineinchlogin_file.readlines (): -USER,PASSWD = Line.strip ('\ n'). Split ()#formats the files that record usernames and passwords and assigns them to user and passwd, respectively +Flog = False#Define a variable A                 ifUsername = = User andPassword = = passwd:#determine if the user name password is correct at                     Print("Landing Success! ") -Flog = True#modifying assigned variables guaranteed to exit the program -                      Break -             ifFlog = =False: -                 ifCount_min < 2: -                     Print("User name password is wrong, please re-enter! ") in                 Else: -Lock (username)#input Error three times the user is added to the lock file toCount_min + = 1 +             Else: -                  Break the  * defLock (username): $With open (locking,'a') as Locking_file:Panax Notoginseng locking_file.write (username) -Locking_file.write ('\ n') the  + if __name__=='__main__': AMain ()
      login.py

Day1 Python Notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.