Python Full stack development day01

Source: Internet
Author: User
Tags terminates

First, Python introduction

The birth and application of Python

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.

Current Python main application areas:

    1. Cloud computing: The hottest language in cloud computing, typically using OpenStack
    2. Web development: A number of excellent web frameworks, many large sites are Python development, Youtube, Dropbox, watercress ... , a typical web framework has Django
    3. Scientific computing, Artificial intelligence: Typical library numpy, SciPy, matplotlib, Enthought Librarys,pandas
    4. System operation and maintenance: the necessary language for operation and maintenance personnel
    5. 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
    6. Graphic GUI:PYQT, Wxpython,tkinter
Second, the Computer Foundation

CPU: equivalent to the human brain, computing and control center. Speed plane

Memory: temporarily stored and supplied with CPU data. Speed HSR. The cost is high and the power loss disappears.

hard disk: the equivalent of a computer database, storage of a large number of data, files, audio files. Speed away. Low cost

operating system: performer, governs all relationships. such as Windows,linux,mac ...

Third, the history of Python

Python 2.6 and 3.0 were born in the same year, 2.6 were October 2008, and 3.0 were December.

Four, Python 2x and 3x differences

Build a blog that specifically stores the differences between 2x and 3x.

1.print methods have different

Python 3x Print (' content ')
Python 2x print () or print ' content '

2. Different encoding methods
Python 3x default encoding: Utf-8
Python 2x default encoding: ASCII contains only English letters and special characters as well as numbers
Chinese not supported
How to resolve:
At the top of the add

#-*-Encoding:utf-8-*-

Input in different ways:

Python 2x:raw_input ()
Python 3x:input ()

V. Classification of developing languages

Vi. Running Python programs

Seven, variable

variables: The intermediate results of running the program are temporarily present in memory for subsequent code calls.

1, the variable must be any combination of numbers, letters, and underscores.

2, the variable cannot begin with a number.

3, the variable cannot be a keyword in python.

4, variables have to be descriptive.

5, the variable cannot be in Chinese.

6, the variable cannot be too long.

7, Official recommendation:

#驼峰体AgeOfOldboy = 56NumberOfStudents = 100# underscore age_of_oldboy = 56number_of_students = 80

It is generally recommended to use the 2nd type, which is the underline method.

Constant

A constant amount, such as Pai 3.141592653 ..., or a quantity that does not change during a program's operation
Default all uppercase variables, called constants.

VIII. Basic data types

String Type (str)

In Python, the quoted characters are considered to be strings!

single quotes, double quotes, and multiple quotes. single and double quotes do not have any difference, only the following situation, you need to consider the single-pair mate

"My name is Alex , I‘m 22 years old!"

What does a multi-quote function do? The function is that multi-line strings must be in multiple quotes. 3 single quotes, which are not assigned, are used to annotate.

msg = "" Today I want to write a poem, praise my deskmate, you see his black short hair, like a fried chicken. "Print (msg)

string concatenation

Only "add" and "multiply" operations can be performed. Multiplied by the number, is the output n times.

int---> str str (12) converted to string, using str ()
STR---> int int (12) All numeric strings can be converted to numbers

Ix. User interaction

View data type: Type ()

X. If statement

The first type of structure

If condition:    result

The second type of structure

If condition:    result else:    result

The third type of structure

If condition 1:    result 1elif condition 2:    result 2elif condition 3:    result 3

The structure of the four

If condition 1:    result 1elif condition 2:    result 2elif condition 3:    result 3else:    result 4

Fifth type of structure

If condition:    if condition:        result    Else: result        else:    result

Xi. and while Loops

Conditions for jumping out of a loop:
1. Changing conditions
2.break, continue

If, for some reason, you do not want to continue the loop during the loop, how do you stop it? This will use the break or continue statement.

    • Break is used to completely end a loop, jumping out of the loop body to execute the statement following the loop
    • Continue and break are a bit similar, the difference is that continue just terminates the loop, and then executes the subsequent loop, and break terminates the loop completely.

Flag-Position Flag

While ... else:

Unlike other languages else, which is usually only the same as if, there is a while ... else statement in Python

The else function behind the while loop is to execute the statement after the else is executed when the while cycle is executed properly and the middle is not aborted.

12. Exercises

1. Use while loop input 1 2 3 4 5 6 8 9 10

2. For all numbers of 1-100

3. All odd numbers in output 1-100

4. All even numbers in output 1-100

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

6. User Login (three chance retry)

"' #第一题count =0while count<=9:count=count+1 if Count==7:continue #跳出某步运行, using continue print (count) "" #第二题count =0sum=0 #为什么要给sum赋初值? It can be understood that when count=1, the above and 0while count<100:count=count+1 #后面的数是在前面的数的基础上加1 sum=sum+count #1到某个数的求和, are the first and the The top and print (sum) ' #第三题 ' Count=1print (count) while count<99:count=count+2 print (count) ' #笨办法, change the idea ' count= 0while count<100:count=count+1 if Count%2==1:print (count) "#第四题" "Count=0while count<100:count=c ount+2 Print (count) "" "Count=0while count<=100:count=count+1 If Count%2==0:print (count)" #第五题 "Co Unt=0sum=0while count<99:if count<=0:count=-(count-1) else:count=-(count+1) SUM=SUM+COUNTP Rint (sum) "#第六题count =0while true:username=input (' account: ') password=input (' Password: ') if username== ' 13699998888 ' and pas sword== ' he8888 ': print (' Congratulations on your successful login and start enjoying the little movie! ') Break else:count+=1 ifCount==1:print (' Account or password error, please re-enter. You have 2 more chances! ') elif Count==2:print (' Account or password error, please re-enter. You have 1 more chances! ') elif count==3:print (' Sorry, your opportunity has been exhausted, the account will be permanently locked! ') break

Python Full stack development day01

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.