The path to Python--Foundation One

Source: Internet
Author: User

Python Introduction

The founder of Python is Guido van Rossum (Guido van Rossum). 1989 Christmas period, Guido van Rossum (Chinese name: Uncle Turtle) in order to pass time in Amsterdam, determined to develop a new script interpreter, as an inheritance of the ABC language.

The July 2017 Tiobe leaderboard, Python has taken the fourth place, Python's elegance, clarity, and simplicity is an excellent and widely used language.

Python application Areas
    • Cloud computing : The hottest language in cloud computing, typically using OpenStack
    • Web Development : A number of excellent web frameworks, many large sites are Python development, Youtube, Dropbox, watercress ... , a typical web framework has Django
    • Scientific Computing, artificial intelligence : Typical library numpy, SciPy, matplotlib, Enthought Librarys,pandas
    • system Operation and maintenance: the necessary language for operation and maintenance personnel
    • Finance : Quantitative trading, financial analysis, in the field of financial engineering, Python is not only used, but also used the most, and the importance of the year. Reason: As a dynamic language Python, the language structure is clear and simple, the library is rich, mature and stable, scientific calculation and statistical analysis are very good, production efficiency is much higher than c,c++,java, especially good at strategy backtesting
    • graphical GUI: PyQT, Wxpython,tkinter
compilation and introduction of Pyhon

CPython: interpreted as C language machine code

Jpython: Interpreted as a Java language byte code

Ironpython: interpreted as C # language bytecode

PyPy: Interpreted as JIT-on-the-fly compilation

Python single-line comments and multiline comments

Single-line comment with "#" in front of content

多行注释  ‘‘‘被注释的内容‘‘‘   或者   """被注释的内容"""concatenation of Strings

The string can only be +, *;

String "+" operation

Boolean value (True, False)

The Boolean value is simple, contains only two values, one represents true (true), one represents false (false)

I now have 2 values, a=3, b=5, I say a>b you say set up? Of course we know it doesn't, but the question is how does a computer describe it as a non-establishment? Or that a< B is set up, how does the computer describe it? Yes, the answer is the Boolean type.

赋值运算

Suppose variable: a = 1,b = 3

1 i = 12 while I <=:34     if i==7 : 5         I+=16         continue7     print(i)8     i+= 1

Logical Operations

Judgment Statement (IF)

If you write a program than do walk, we have so far, have been walking straight, have not encountered too much fork, imagine the reality, you encounter a fork, and then you decide where to turn must be motivated. You have to judge that fork is the way you really want to go, if we want to let the program can also handle such a judgment what to do? Very simple, just need to preset some conditions in the program to judge the sentence, to meet which conditions, the road fork. This process is called Process Control.

Single Branch
1  if Conditions: 2      Code to execute when the condition is met
Dual Branch

1  if Conditions: 2 Code 3      that satisfies the conditional execution  Else : 4      If condition does not satisfy go this paragraph

if score >=:3     print(" pass ")Else :5     print(" less than grid "
Multiple Branches

if Condition:    The code that satisfies the condition executes elif  Condition: The    above condition does not satisfy to go this paragraph elif  Condition: The    above condition is not satisfied to go this paragraph elif conditions:    The above conditions are not satisfied and go this paragraph else  :    All the above conditions are not satisfied and go this paragraph

1Age = 482 3guess = Int (input ("Please enter the age you want to guess:"))4 ifGuess >Age :5     Print("guess big, try the little Li ...")6 7 elifGuess <Age :8     Print("guess small, go to Dali try ...")9 Else:Print("Congratulations, you guessed it.")

Looping Statements
    • In general, code that requires repeated executions can be done in a circular way

Cyclic termination conditions:

    1. The Break keyword
    2. Changing the while loop condition
    3. Continue

....  while conditions:      When conditions are met, do things 1      conditions meet, do things 2      when conditions meet, do things 3      conditions do not meet, jump out of the loop, execute while the following code ....

Continue keywords

For example, print 1-10, but do not print 7, 1,2,3,4,5,6,8,9, 10, you can use continue, when the variable equals 7, jump out of this cycle, the next cycle

i = 1 while I <=:    if i==7 :        i+=1        continue     Print(i)    i+=1
The break keyword
i = 1 while I <=:    if i==7 :        break    print(i)    I+=1

only executes to 7, interrupts the loop, and the subsequent array no longer prints the output .

Related Work Problems1.using while loop input 1 2 3 4 5 6 8 9

# 1 2 3 4 5 6 8 9n = 1 while n <=:    if n! = 7:        Print
   
     (n)    
    Else
    :        
    print
    ()    + = 1
   
loop output 1-10, excluding 72. for all numbers within 1-100 and

n = 1= 0 while n <=:    print(    sum)+ = N    + = 1
1-100 All and

3.Enter all the odd numbers within 1-100

y = 1 while y <=:    if y% 2 = = 1:        print(y) c21/>+ = 2  #  ' + = ' equals y = y + 2
1-100 all odd numbers

4. Enter all the even numbers within 1-100

x = 1 while x <=:    if x 2 = =0:        Print(x)    + = 1
1-100 all even numbers

5. all the numbers of 1-2+3-4+5....99 and

A = 1= 0 while a  <=99:     if#  % represents the remainder.         B = A + b     else:         = B- a     + = 1     Print  (a)     print(b)
Question Fifth

6. User login (three chance retry )

Number =0name="Mr. Wang"Password="1223" whileNumber < 3: number+ = 1name2= Input ("Please enter user name:") Password= Input ("Please enter your password:")    ifname2 = = Name andPassword = =pawd:Print("Enter the correct")         Break    Else:        ifNumber = = 3:            Print("excessive number of input errors, please try again in three minutes")        Else:            Print('input error%d times, please re-enter! '%number)
User Login

The path to Python--Foundation 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.