2018-5-22-python Full Stack Development Day9-python Development Course Introduction Part2

Source: Internet
Author: User

1.Python Installation 1.1

The current learning trend is to use Python3, which requires clicking the add to the PATH environment variable when installing. If the environment variable is not set at Python2, it is troublesome to find the path of Python every time under the command, such as:

Python a.txt, the environment variable is set up properly, the system will automatically complete the file path before Python, and then find Python.exe, if the computer installed Python2 and Python3, then you can modify the name of Python.exe to distinguish. 2.python suffix typically python can recognize non-py suffixes, but when importing a module, it must be a py suffix, so by default, the Py suffix is easy to identify. 2.1 Code lines Writing default rules in general, it needs to be noted that: #!/usr/bin/env Python, mainly under the Linux system, declares the interpreter used, the-*-coding:utf8-*-encoding declaration, the use of Chinese-supported encoding, In Python2 need to declare, otherwise Chinese will be garbled, in Python3 built-in, no need to declare. 3.input operation input is to let the user enter a data, before the user enters data, the calculator waits by default, obtains the user input data, then starts the next line of command:
A=input (' This was my New life ') print (a)

By assigning the data entered by the user to a, and then entering a, the data entered by the user is printed out, a can also be called a variable, the variable is the value of the change, refers to a real value, 3.1 variables of the canonical variable can only be 1. Number 2.3. Underline these three types, and the name number of the variable can not be in the first place, when the variable is named, you should avoid (must) with Python built-in keyword duplication such as list, etc., if the repetition may lead to unknown errors. 4. The conditional statement condition statement is the IF, else, elif rule:
If condition: Then else: Then:

Example:
If A==a:    print (' Your home ') Esle:    print (' Hello World ')

4.1 Nested examples
If a==a:    if b==b: print (    ' B ')    else:    print (' a ') Else:    print (' Qiantao ')

4.2pass usage If you meet a certain condition, but you do not want to do anything, you can use pass to skip, cannot write anything, such as:
If a==a:    passesle:    print (' Hello World ')

5. Basic data Type 5.1 strings all enclosed in quotation marks are characters, collectively referred to as strings, ', ', ', ' and ', ' only these three are strings, and starting with a quotation mark must end with the same quotation mark. Addition of strings:
A= ' Alex ' c= ' sb ' n=a+cn= ' ALEXSB '

Multiplication of strings
B=a*10b= ' Alexalexalex ... ' 10 total

5.2 Numbers without quotation marks, with normal arithmetic, and a**4 is four times a, a%2 is the remainder of a divided by 2, A//2 is to get a divided by 2 quotient 6. Cyclic while6.1 dead loop
While 1==1:    print (' AA ')

As long as the condition is true, the code within the loop block is continued. 7. Job 7.1 using while loop output 1234568910
N=1while n <11:    if n = = 7:        pass    else:        print (n)    n=n+1        

Effect 7.2 for 1-100 number and
N=1a=0while n <101:    a=a+n    n=n+1    Print (a)    

Output 7.3 To find all the odd numbers within 1-100
N=1while n<101:    if n%2 ==1:    print (n)    n=n+1

7.4 1-100 in all even
N=1while n<101:    if n%2 ==0:    print (n)    n=n+1

7.5 Output 1-2+3-4...99
N=1a=0while n<101:    if n%2 ==1:        print (n)        a=a+n    Else:        print (n)        a=a-n    N=n+1print (a)                

7.6 User Login, three login opportunities, three times cannot login
A= ' root ' n=1while n<4:    b= input (' ddd ')    if a = = B:        print (' Welcome ') Break    else:        Pass    n=n+1            

2018-5-22-python Full Stack Development Day9-python Development Course Introduction Part2

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.