Python diary--writing python for the first time

Source: Internet
Author: User

"Hello World"    
1  # ! /usr/bin/env python2  #  -*-coding:utf-8-*-3  4      Print ('hello,world')

when the line stares: # is annotated content

Multiline Comment: "" "Annotated Content" ""

"Print user input user name and password"
     

1 a1 = Raw_int ("UserName")2 a2 = Getpass.getpass (" PassWord " )34Print(A1)5Print(A2)

[Ps:getpass.getpass Assigning user input to name variable] does not show password when input


"Writing and executing Python code flow grooming"1. Create a xxx.py file
PS: Do not have Chinese path
2. Write code
A. Two lines of the head specific
#!/usr/bin/env python (Specify editor path in Linux)
#-*-Conding:utf8-*-
B. Write function code
3. Execute code
A. Open the terminal
Path to the B.python code file
11. Create a xxx.py file2 PS: Do not have Chinese path32. Write Code4 A. Two lines of the head specific5         #!/usr/bin/env python (Specify editor path in Linux)6         #-*-Conding:utf8-*-7 B. Write function code83. Execute code9 A. Open the terminalTenPath to the B.python code file

"python variable"1.python2.7 is using "raw_input" to complete waiting for user input
    • Example: 1 raw_input ('>>>')
python3.5 is using "input" to finish the place. User Input
    • Example: 1 input ('>>>')
 PS: Variables are used to give specific ' things ' to the meaning--variable assignment2. Limitations in Variables
    • Variable name: function with numbers, letters, underscores
Example: 1 a1 = ABC 2 A_BC = 123 Example: 1 name1 = "ABC" 2 name2 = name1 so name2 = " /c13>ABC"
    • Cannot start with a number
    • Variable cannot be a keyword inside python
        
PS: Write code in the IDE if you encounter an internal variable editor, you will be prompted
"Basic data Type"1. Number: 1234
    • Example: 1 ABC = 1234
2. String:
    • Cases:
      1 " ABC " 2 ' BCD ' 3 a3 =  "" "abc12 " ""

3. Boolean value:True/falsetrue 
    • Data is true--a results
    • Data is false--b result
     
Ps:true/false First Letter Capital

  "Basic conditional statement One"
1 if Condition:                      established                                                   2           content one 3           content two 4Else  :                           not set up 5           content 6           content four 7           

Ps:
  1. If Else statement
  2. Symbols written in English
  3. "=" An equal sign is an assignment
  4. "= =" Two equals is a comparison
  5. "! =" does not equal
   "Basic conditional statement two"   
1Name = Raw_input ("UserName") 2PWD = Raw_input ("PassWord") 3 ifName = ="ABC"  andPWD = ="123":4      Print('Yes')5 Else:6      Print('No')

  "Basic Conditional Statement three"--Multiple conditions comparison
1 if Condition One: 2           xxxx3elif  condition Two:4          xxxx5elif  Condition Three:6          xxxx7Else:8           AAAA       9

   "First real while loop" "First real while loop"While condition: code block Example:
1 imput Time 2        while True: 3               Print ('1') 4               TIME.SLOSP (1)5     print('end')

    • Terminating a while loop with conditional statements
Basic Loop: Example:
1   n1 = True2while    N1:3        print(' 123 ' )4         n1 = False5   print('end ')

    • Break: Used to jump out of the current loop, and the code below the break is not executing.
    • Conttinue: Used to jump out of this loop and continue the next cycle

 

Python diary--writing python for the first time

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.