Python Learning Path One

Source: Internet
Author: User

Tag: User input password disable display size exec return lower

One: Notes

When the line stares: # is annotated content

Multiline Comment: "" "Annotated Content" ""

II: PYC File

When the Python code is executed, another. py file is imported, and a. pyc file with the same name is automatically generated during execution, which is the bytecode generated by the Python interpreter after compilation.

PS: Code is compiled to generate bytecode, and bytecode can be obtained by decompile.

Python compilation process:

The Python interpreter converts the source code into bytecode and then executes the bytecode by the interpreter .

The virtual machine executes the script process:

1. Complete the module loading and linking

2. translate the source code into the pycodeobject object (this is the bytecode) and write it into memory (to facilitate the CPU to read, play a role in accelerating the operation of the program);

3. Read instructions from memory space and execute

4. After the execution of the program, depending on the command line (that is, the way to run the program) to determine whether to write pycodeobject back to the hard disk (that is, directly copied into the. pyc or. pyo file);

5. then, if you execute the script again, check that the local byte-code file is there. If you do, repeat the steps above

Three: Define variables:

A variable can contain only letters, numbers, and underscores. Variable names can begin with a letter or underscore, but not with a number. Variable names cannot contain spaces, do not use Python keywords and function names as usernames

Variable names should be both brief and descriptive, with caution in lowercase l and capital letter O

The following keywords cannot be declared as variable names
[' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' Global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ']

Four: string:
* The parentheses in Python are strings, where the quotation marks can be single quotes or double quotes

"This is a string"

' This is also a string '

* Modify the case of the string:

. Title () displays each word in an uppercase letter

. Upper () Uppercase output

. lower () lowercase output

. Rstrip (). Lstrip (). Strip () remove whitespace, this deletion is temporary, and the next call is still blank

User login limit three times, three times after lock account

1Username="Admin"2Passwd="12345"3Fp=open ("./test.txt","R")4Count=Fp.read ()5 ifLen (count) = =0:6Count=07      whileCount<3:8User=input ("Please enter user name:")9Password=input ("Please enter your password:")Ten         ifUser ==username andpassword==passwd: One             Print("Welcome to login") A              Break -         Else: -             Print("try Anger") theCount+=1 -     Else: -         Print("you have lost three times the password, the account is disabled") -F=open ("./test.txt","W") +F.write ("User name:"+user+"Password:"+password) - f.close () + Else: A     Print("your account has been frozen please contact the Administrator")
View Code

Loops: While for

Break: Used to exit all loops

Continue: Jump out of this cycle and continue to the next loop

Python Learning Path One

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.