Python Foundation One

Source: Internet
Author: User
Tags terminates

Python Foundation One

First, Python history

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.

(Uncle Tortoise: 2005 joined Google to 2012, 2013 joined Dropbox until now, still grasp the core direction of Python development, known as benevolent dictator).

Ii. History of Python

  • In 1989, in order to pass the Christmas holiday, Guido began to write the Python language compiler. The name Python, from Guido's beloved TV show Monty Python's Flying Circus. He hoped that the new language, called Python, would fit his ideals: create a language that is all-powerful, easy to learn, easy to use, and extensible, between C and Shell.
  • 1991, the first Python compiler was born. It is implemented in C language and can call the C language library file. From birth, Python already has: classes, functions, exception handling, core data types including tables and dictionaries, and module-based expansion systems.
  • Granddaddy of Python Web frameworks, Zope 1 is released in 1999
  • Python 1.0-january 1994 adds lambda, map, filter and reduce.
  • Python 2.0-october 16, 2000, added a memory recovery mechanism that forms the basis of the Python language framework Now
  • Python 2.4-november 30, 2004, the same year now the most popular web framework Django was born
  • Python 2.5-september 19, 2006
  • Python 2.6-october 1, 2008
  • Python 2.7-july 3, 2010
  • In November, it is announced that Python 2.7 would is supported until 2020, and reaffirmed that there would is no 2. 8 release as users were expected to move to Python 3.4+ as soon as possible
  • Python 3.0-december 3, 2008
  • Python 3.1-june 27, 2009
  • Python 3.2-february 20, 2011
  • Python 3.3-september 29, 2012
  • Python 3.4-march 16, 2014
  • Python 3.5-september 13, 2015
  • Python 3.6-december 16,2016

Iii. Division of language

Compile: Compile your code all at once into binary, then run.
Disadvantage: The development efficiency is low, cannot cross the platform.
Advantages: High execution efficiency.
Representative: C

Explanatory: When the program starts running, it interprets the line of code as binary (with sound translation) and executes.
Disadvantage: Low execution efficiency.
Advantages: The development efficiency is high, can cross the quality table.
Rep: Python

V. Types of Python

1, CPython

When we downloaded and installed Python 3.6 from the official Python website, we immediately got an official version of the interpreter: CPython. This interpreter was developed in C language, so called CPython. Running at the command line python is to start the CPython interpreter.

CPython is the most widely used Python interpreter. All the code for the tutorial is also executed under CPython.

2, IPython

Ipython is an interactive interpreter based on CPython, meaning that Ipython is only enhanced interactively, but the functionality and CPython of executing Python code are exactly the same. Like many domestic browsers although the appearance of different, but the kernel is actually called ie.

CPython >>> is used as a prompt, while Ipython is used In [ 序号 ]: as a prompt.

3, PyPy

PyPy is another Python interpreter whose goal is to perform speed. PyPy uses JIT technology to dynamically compile Python code (note that it is not interpreted), so it can significantly improve the execution speed of Python code.

Most python code can run under PyPy, but PyPy and CPython are somewhat different, which results in the same Python code being executed under both interpreters. If your code is to be executed under PyPy, you need to understand the differences between PyPy and CPython.

4. Jython

Jython is a Python interpreter running on the Java platform that compiles python code directly to Java bytecode execution.

5, IronPython

IronPython is similar to Jython, except that IronPython is a Python interpreter running on the Microsoft. NET platform that compiles python code directly into. NET bytecode.

Summary:

Python has a lot of interpreters, but the most widely used is cpython. If you want to interact with the Java or. NET platform, the best approach is not to use Jython or IronPython, but to interact via network tuning to ensure the independence of each program.

Vi. basic knowledge of Python

1, the operation needs to have EXECUTE permission, interpreter

#!/usr/bin/env python#-*-encoding:utf-8-*-

2. Comments

When line comment: # is commented content

Multi-line Comment: ' Annotated content ', or ' "' annotated Content '" "

3. Variables

What is a variable? Variables: The intermediate results of running the program are temporarily present in memory for subsequent code calls.

#变量赋值
#一个等号是赋值 two equals equals #!/usr/bin/env python#-*-coding:utf-8-*-name1 = "Wupeiqi" name2 = "Alex"

  

Variable rule:

1, the variable is any combination of alphanumeric underlines. 2, the variable cannot be the beginning of a number. 3, the variable cannot be a keyword in python. [' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' fr ' Om ',  ' global ', ' if ', ' import ', ' in ', ' was ', ' Lambda ',  ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ',  ' try ', ' While ', ' with ', ' yield ']4, variables to be descriptive.    NAME,AGE,FDASGFDAS5, variables cannot be used in Chinese. 6, variable cannot be too long define the way the camel body is underlined    Ageofoldboy =    numberofstudents = 80# underline    Age_of_oldboy =    number_of_students = 80

4. Constants

#常量: Constant amount. π, founding of New China 1949101# the variable of all uppercase is constant. On top of the file.

5. Basic data type

int: number: calculated. + = */%//... Str:python quoted in quotation marks is called a string ("  " ").    type (object) is what data type is    useful: storing simple small amounts of data.    +    *    + concatenation of strings.    * str* Intbool:true,flase
  
#type () View type
Print (666,type (666)) print (' 666 ', type (' 666 ')) msg = "My name is Alex, I ' m" Years old! " msg = "" Today I want to write a poem, praise my deskmate, you see his black short hair, like a fried chicken. "Print (msg)

#字符串拼接a = ' old boy ' B = ' is the best training institution ' C = a + b #相加其实就是简单拼接
Print (c) print (' strong ' *8) print (2 > 1)
#相乘其实就是复制自己多少次, and then stitch together

6. User interaction (input)

Input data types are all strings. Name = input (' Please enter your name: ') Sex = input (' Please enter your gender: ') print (' My name is ' + name ', ' my gender is ' + sex ')

7. Formatted output

#格式化输出% Placeholder  s (string)  D (number),,, format strong forwarding PS  str--> int  str All consist of numbers ' 1234 ' PS  INT--> str  str ( int),,, #第一种表现形式: replace name with a tuple (' Enter your Name: ') Age = input (' Please enter your age: ') job = input (' Please enter your work: ') hobby = input (' Please enter your hobby: ' ) MSG1 = "------------info of%s-----------Name  :%sage   :%djob   :%shobbie:%s-------------End---------- -------"% (name,name,int (age), Job,hobby) #int () strong to digital type print (MSG1) #第二种方法: replace dic with a dictionary = {' name ': ' Old boy ', ' age ': 45, ' Job ': ' Teacher ', ' hobby ': ' blow '}MSG1 = '------------info of% (name) s-----------name  :% (name) SAge   :% (age) Djob   :% (Job) Shobbie:% (Hobby) s-------------end-----------------'% dicprint (MSG1) #单纯只显示%, front plus% escaped MSG2 = ' I'm%s, this year% s, learning Progress 5% '% (' taibai ', ') print (MSG2)

7. If statement

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.

If...else statements

#单分支if Condition:    code to be executed after the condition is met # Double branch "" If condition:    satisfies the conditional execution code else:    If condition does not satisfy go this paragraph "" "Ageofoldboy = 48if ageofoldboy > 50:    print ("Too old, time to retire ...") else:    print ("Can still toss for years!")

 

#多分支,,, if condition:    satisfies the condition execution code elif condition: The    above condition does not satisfy to go this elif condition: The    above condition does not satisfy to go this elif condition: The    above condition does not satisfy to go this    else:    all the above conditions are not enough to go this paragraph,,, num = int (input (' Guess number: ')) if num = = 6:    print (' Please eat ') elif num = = 3:    print (' please drink ') elif num = = 1:    print (' Please you Big Health ') more than 4 conditions required one result num = Int (' Guess number: ') if num = = 6:    print (' Please eat ') elif num = = 3:    print (' Please drink ') elif num = = 1:    print (' ask you to care ') Else:    print (' no chance ..... ') score = int (input ("Enter score:")) if score > 100:    print ("I rub, highest score ...") Elif score >=:    print ("A") elif score >=:    print ("C") elif score >= 80 :    print ("B") elif score >=:    print ("D") Else:    print ("Too stupid ... E ")

#这里有个问题, when I entered 95, it printed the result is a, but 95 is clearly greater than the second condition elif score >=80: Ah, why not print B? This is because the code is from top to bottom in order to judge, as long as the satisfaction of one, it will not go down, it must be clear!

8. While loop

While condition:         # loop Body     # If the condition is true, then the loop body executes    # if the condition is false, the loop body does not execute

9. Cyclic Abort statement

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.
    • #如何终止循环: #1, change the condition.  #2, Breakcount = 1while count <=:    print (count)    count = count + 1 # Count + = 1 Front-same count = 1flag = Truewhile Flag:    Print (count)    count = count + 1    if Count = = 101:        flag = Falsecount = 1sum = 0while Count < 101:
           sum = Sum +count    count + = 1print (sum) #while keyword: Break,continue#break end loop. #continue jump out of the loop and proceed to the next loop. While true:    print (333)    print (5455)    print (222)    Break    print (888) print (666) while true:    Print (333)    print (222)    Continue    print (888) print (666) #while else: If the while loop is interrupted by a break, Don't go. Elsecount = 1while Count < 5:    print (count)    count + = 1else:    print (' Loop OK ')

10. Operators

Arithmetic operations

  

Comparison operation

  

Assignment operations

  

Logical operations

  

In the absence of () the not priority is higher than the And,and priority above or, i.e. the priority relationship is () >not>and>or, and the same priority is computed from left to right.

1,3>4 or 4<3 and 1==12,1 < 2 and 3 < 4 or 1>2 3,2 > 1 and 3 < 4 or 4 > 5 and 2 < 14,1 > 2 an D 3 < 4 or 4 > 5 and 2 > 1 or 9 < 85,1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 66, Not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6

  

  

Seven, the difference between Python2 and Python3

1, python2x: source duplication, not standard
Python3x: Integrate the source code, more clear and simple beautiful.

2, PYTHON2X: The default encoding is ASCII,
Solution: #-*-Encoding:utf-8-*-
PYTHON3X: The default encoding is Utf-8

3, Python2x:long int
print ' ABC ' Print (' abc ')

PYTHON3X: no long int
Print (' abc ')

4, Python2x:raw_input ()
Input () can only enter numeric types
Python3x:input

Viii. Related Exercises

#1, using while loop input 1 2 3 4 5 6     8 9 10n = 0while n <=:    n + = 1    if n = = 7:continue    print (n,end= "") #2, ask for 1-1 00 of all numbers and num = 1Sum = 0while num < 101:    sum = sum + num num + =    1print (sum) #3, output 1-100 for all odd-I in range (1,100 , 2):    print (i,end= "") #4, output 1-100 all even for I in range (0,100,2):    print (i,end= "") #5, ask for 1-2+3-4+5 ... 99 of all numbers and 1, sum1 = 0     sum2 = 0 for     i in range (1,100,2):         sum1 = sum1 + i for     o in range (0,100,2):        sum2 = sum2 + o     print (sum1-sum2) 2, Print (sum ([x if x%2 = = 1 Else-x for x by range (1, 100)])) 3,    num = 0 for    i I N Range:        if i%2 = = 1:            num + = i        else:            num-= i    print (num)

  

Python Foundation One

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.