python basis (a) -day01

01. the source of all evil -python basis
⼀ introduce a .python
founding the Face of man-made python Guido van Rossum (Guido van Rossum). Every year during the Christmas season of 1989, Guido
Fanluosumu To pass the time in Amsterdam Dan, Center Weighted heart must develop ⼀ a new script interpreter, as ABC your language and words of ⼀ Yi
Zhong inheritance.
The latest row ⾏ trekking TIOBE list, Python has occupied the fourth position in the world, Python advocating beautiful, clear, simple
single, is a good ⼀ and Wide-wide Using the language used The language statement.
⻅ can see from the chart, Python overall upward trend, reflecting the use Python to apply it more widely and Wide-industry has gradually been
recognized! ! !
Use Python can be used in many fields, such as: data analysis, component integration, ⽹ network services, processing of the image processing, numerical
fields and scientific computing. Almost all of the industry's destination time to get accustomed zoomed medium-sized enterprises in the Internet network ⽹ Use with Python, such as:
Youtube, Dropbox, BT, Quora (China know almost), ⾖ watercress, know almost, Google, Yahoo !,
Facebook, NASA, Baidu, Tencent, steam ⻋ car home, the US group and so on.
Python is currently the main destination time to apply it with areas:
cloud computing: Cloud computing in fire fire most of your language and speech, typical to apply it with OpenStack
WEB development: many excellent WEB framework, many sites are zoomed large ⽹ Python development, Youtube,
Dropbox, ⾖ watercress. . . Typical WEB framework Django
scientific computing, people ⼯ Face artificial intelligence: Typical library NumPy, SciPy, Matplotlib, Enthought
librarys, pandas
system operation and maintenance: Face of operation and maintenance personnel must have your language and speech
⾦ financial gold: the amount of quantitative trading is easy, ⾦ gold financial analysis, financial ⼯ gold in ⾦ engineering, Python is not only used in Use, and Using the most used , while ⽽
and the importance of the year in response to high high. The reason: as a dynamic words of your language and Python, your language and word structure clear and straightforward, rich library,
mature and stable, scientific computing and statistical analysis are ⽜ regressed, ⽣ productivity is much higher than the ADVANCED c, c ++, java, especially in trespassing ⻓ long
policy strategy backtesting
graphics the GUI: PyQT, WxPython, TkInter
Python should ⼀ use some companies use:
⾕ Google: Google App Engine, code.google.com, Google earth, Google ⾕ climb ⾍ insects,
Google Wide-advertising item destination time a large number of projects in the amount of maximum usage in Python developers
CIA: CIA ⽹ site is developed in Python using
NASA: US space Agency (NASA) zoomed by a large number of volume using Python trekking into ⾏ data analysis and computation
YouTube: the world's most zoomed large video ⽹ site YouTube is using a Python development of
Dropbox: America is largest large online cloud storage ⽹ website, all using implemented in Python, ⽹ site to handle processing 1 billion a day
files file upload and download
Instagram : the United States is largest big piece of still pictures map share social ⽹ sites, more than 30 million pieces every day by sharing a picture Business cards, all with using
python development
Facebook: a large number zoomed amount of base libraries are implemented by Python
Redhat: the world's most stream ⾏ trekking ⾏ Linux version trekking Hair yum package management tool is the reason ⼯ Using a python development
⾖ watercress: Companies get accustomed almost all business are developed by Python
know almost: the most Q zoomed large community, through the Python development (foreign Quora)
spring rain to rain, your physician born: a well-known site is the online medical ⽹ using a Python development
outside ⾯ face on the addition, as well as Sohu, ⾦ Gold ⼭ Hill, Tencent, Sheng zoomed large, easy to ⽹ Netease, Baidu, a ⾥ ri, Taobao, ⼟ soil ⾖ beans, new
wave, shell and other companies are using to complete various tasks using Python.
1.1.python is ⼀ a ⻔ door even what your language and speech
programming your language and speech mainly from the following several ⻆ angle to get accustomed to trekking into ⾏ classification, compiled and interpreted, static dynamic your language and your language and words and words, strong class
type defined in your language and your language and define words and weakly typed words, we look at the words and compiled your language and your language and interpreted the words. later Besides strong typing and weak class
type
What is the difference between compiled and interpreted what?
The compiler is the source sentence each ⼀ statement are compiled into machine your language and speech, and save the file to ⼆ binary files, so when running a computer trekking
can machine your language and speech when running a trekking to direct this program , very fast;
⽽ while an interpreter is only when perform trekking program, only ⼀ a ⼀ interpreted as a machine of your language and words to perform trekking to the computer, so when running a trekking speed
is not as good as compiled when running a program after trekking the fast.
this is because the computer can not directly recognize and perform trekking we write sentence statement, it can only recognize the machine your language and speech (is ⼆ binary form)

Compiled vs interpreted
compiled
advantages: Compiler ⼀ generally have precompiled code into ⾏ trekking process optimization. ⼀ because the compiler only once, when coding is not required when running a trekking
translation, so compiled your language and speech programs Perform trekking ADVANCED high efficiency. It may be out of your language and locale when running a separate trekking.
Cons: After compiling If you need to modify the entire module needs to be recompiled. Compile time when running a trekking according to the corresponding environmental ⽣ born
into machine code, there will be a migration issues between different operating systems, depending on the required operating system environment when running a compiled trekking
can Perform trekking files file.
Interpreted
advantages: a good platform compatibility, in any environment can be when running a trekking, provided that the interpreter (Virtual Machine) installed a.
Flexible and modify the code directly modify when you can, you can quickly deploy, will not be used for maintenance downtime.
Cons: every time when running a trekking must explain ⼀ again, not as good as the performance of compiled your language and speech.
The advantages and disadvantages of 1.2.python
look at the advantages of
1. Python position is "elegant" and "clear", "simple", so Python program always looks Yiyi simple
to understand, beginners learn Python, not only the START door ⻔ easy easy, ⽽ and into the future START deep down, you can write that comes in handy very comes in handy very
complex procedures.
2. ADVANCED development efficiency comes in handy very high, Python has a very powerful comes in handy ⽅ zoomed third party library, you basically want to achieve through any computer
functions, Python official ⽅ party libraries ⾥ ri has a corresponding module into ⾏ trekking ⽀ support, after adjusting use Download used in library-based base
on the basis trekking charge before development, large zoomed zoomed greatly reduced development cycle, sub-submenus wheel made to avoid duplication.
3. ADVANCED Senior your language and words ---- when you Use The language for the words to write programs in Python language, you need to consider, such as how to manage ⽆ care about you
The program causes a low-level details of memory ⼀ Use with class
4 portable ---- Due to its open nature, Python has been ported on many platforms (through changes
it is not possible to work on different platforms ⼯ in) . If you ⼩ Center Weighted carefully refrain from using a small used depends on the nature of the system, then you are
all Python programs without modification ⽆ when running a trekking permit low almost on all platforms on the market
5. Scalability ---- If you need your ⼀ a critical piece of code when running a faster and more trekking or want some algorithms are not unfair
to open, you can put part of your program use written in C or C ++, and then use use in your Python programs manipulation they.
6. START can be embedded into sexual ---- you can put Python START embedded into your C / C ++ programs, and provide your program from ⽽ to Use user
scripting capabilities.
Look Disadvantages:
1. slow, Python's speed when running a trekking with ⽐ The language words indeed much slower than the C language, with JAVA phase ⽐ ratio needs to slow ⼀ number, so
this is a lot of so-called big ⽜ cattle zoomed not disdain using the main reason to use Python, but in fact when running a speed trekking referred to in individual cases from inside
slow ⽆ using the user is unable to directly perceive zoomed in most cases, must rely on test tools can be reflected ⼯, ⽐ For example,
you spend using a program in C op ⼀ of the 0.01s, use in Python is 0.1s, so C your language and words directly ⽐ Python faster than the 10 times,
be very exaggerated comes in handy, but you are not directly ⽆ ⾁ perceived by the naked eye, because when only one Face a normal person can perceive
between the most ⼩ small units is about 0.15-0.4s, ha ha. In fact, in most cases zoomed Python has been completely filled
EMPTY full requirements of your program speed, unless you want to write for non-comes in handy in extremely high speed requirements of high search engine such as, in this case, when
then it is recommended that you use Use C to achieve.
2. The code does not encrypt, because PYTHON interpretative your language and words, its source code is stored in the name of the file in the form of text, no, no
me do not do not think this be a drawback ⼀, if you the item you source project requirements code must be encrypted, then you start ⼀
not use should not come with Python implementation.
3. Use Lilly thread does not use multi-CPU problem, this is Python Face criticized by most ⼀ a drawback, GIL namely global interpreter
device lock (Global Interpreter Lock), is a computer programming your language and an interpreter Using words used to synchronize threads
⼯ tool, so that any time only one thread in ⼀ perform trekking, Python threads are original ⽣ operating system native threads.
On Linux is pthread, on Windows Win thread, entirely by the operating system thread scheduling
Perform trekking. There ⼀ a main thread, as well as trekking Perform Using multiple threads within the user program ⼀ a python interpreter processes. That is
the platform on a multicore CPU, because of the GIL, it is prohibited only multi-threaded and ⾏ trekking YES trekking. On the subject
of compromise Remedies method, we then discussed in detail at a later trekking into ⾏ threads and processes chapters ⾥ ri.
Of course, Python as well as some other ⼩ ⼀ small shortcomings, this is not a ⼀ a ⼀ not listed, I want to say is, whichever is a door ⻔ language
The language is not speech is not perfect, there are good at ⻓ long and not good at ⻓ long to do, does not suggest that they do not take ⼀ a disadvantage language the language for the words to talk to a another ⼀
your language and words come and go ⽐ comparative advantage, your language and the words just ⼀ ⼯ a tool to achieve program ⼯ tool designer thought, before we just like in
the time to get accustomed to learn geometry, sometimes need to compasses, sometimes need using a three ⻆ Square ⼀ like to work surely take the appropriate tool to do it had been masters
⻓ long what is the right choice. Many people have asked me before Face Shell and Python in the end which is better? I replied that Shell is
Script your language and words, but not more than just a Python script your language and words, can do more and more, and then have a separate warranty drill ⽜ cattle ⻆ sharp angle Face said absolutely
no need to learn Python, Python can do Shell can do, as long as you EMPTY enough ⽜ cow B, then she gave a separate warranty use with Shell
can write Russia ⽅ box this game, which I can only say that the expression is not reason not to follow the theory SB, SB will you pulled with
his ⼀ ADVANCED same height, and wipe with a full experience you down.
1.3.python interpreter is
when we write Python code, we get to .py extension of the file that contains the text ⼀ Python code
files file. When running a trekking to the code, you need to go to the Python interpreter is YES trekking .py files file.
Since the entire Python your language and words from specification to an interpreter are open source, so management theory, as long as water resistant ADVANCED level high enough, Face any person
can write Python interpreter is to Perform trekking Python code (of course, very difficult zoomed large). In fact, the existence of multiple
Python interpreter is.
CPython
when we download and install Python 2.7 from Python official ⽅ party ⽹ site, we just received the official ⽅ ⼀ a square version
of this interpreter is: CPython. Using the interpreter is your language and speech development in C, so called CPython. At the command ⾏ trekking shipped
⾏ trekking python is to start CPython interpreter device.
Using CPython is the most extensive full wide Python interpreter is. All tutorials are also in the code under CPython Perform trekking.
IPython
IPython is based on the ⼀ CPython is an interactive interpreter, that is to say, IPython only interaction ⽅ party
The formula has been enhanced, but the Perform trekking Python code is fully functional and CPython ⼀ same. ⽐ better than many domestic browser
is not an appearance, although different, but the core are actually tune with the Use of IE.
Use as a CPython >>> prompt, and ⽽ with IPython Use In [ID]: as a prompt.
PyPy
PyPy is another ⼀ a Python interpreter is, its goal is YES trekking destination time speed. JIT PyPy recorded using a technique of substituting Python
code compilation into dynamic ⾏ trekking (not careful not explained), it is possible to significantly improve the high speed ADVANCED YES trekking Python code.
The absolute majority of Python code can be zoomed when running a trekking in PyPy, but CPython PyPy and there are not a number of different ⼀, which
lead to the same Python code Perform trekking in both the interpreter may not have different results. If your code is to put
YES trekking under PyPy, you need to understand the differences PyPy and not of CPython.
Jython
jython is trekking when running a Python interpreter in the Java platform, can be directly Python code is compiled into Java byte
code YES trekking.
IronPython
IronPython and Jython similar, but not IronPython is only when running a trekking on the Microsoft .Net platform solution Python
interpreter, you can compile Python code directly into .Net byte code.
⼆ two .python history of
mid-1989, in order to pass the Christmas holidays, Guido (⻳ turtle t) began to write the words of your language and Python compiler is.
Python name to Guido automatically from the beloved TV series Monty Python's Flying Circus. he
This new hope is called Python's your language and words, able to meet his physical ideal: to create ⼀ between one C and shell, functional
whole ⾯ surface, easy to learn and easy to use Use Yiyi, extension to expand your language and speech.
Mid-1991, the first frame is a Python compiler birth ⽣ students. It is your language and speech Using the C implementation, and can be adjusted with C Using the words of your language and library
files file. From birth ⼀ a ⽣, Python already has: the classes, functions, exception handling processing, tables and dictionaries, including the
core Center Weighted core data type, and a module-based expansion system extension.
Granddaddy of Python Web frameworks, the Zope. 1 WAS Released in 1999
Python 1.0 - January 1994 increase of the lambda, Map, filter and the reduce.
Python 2.0 - October 16, 2000, filling with the into the memory recovery mechanism, constituted now Python your language and words
the basic framework of
Python 2.4 - November 30, 2004, the same year in most streams ⾏ trekking destination time of birth ⽣ Health WEB framework Django
Python 2.5 - September 19, 2006
Python 2.6 - October 1, 2008
Python 2.7 - July 3, 2010
an In November 2014, IT WAS Announced Set that Python 2.7 Would BE
Supported an until 2020, and reaffirmed that there BE NO Would Release 2.8
the Move the Users were expected to AS to AS Soon AS Possible Python 3.4+
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
three .python installation
⼀ way to remember tick under way to determine the path..
four first frame a python program.
python program written ⽅ two ways:
1. enter cmd into the python console input editor. the pattern this time we can write directly python program
2. You can also write python code files .py file to perform trekking through the python code python command.
Note: in the text encoding files have problems python2 in python2 Use use the ASCII code encoding process is not a reason in text files I..
we need to replace the utf-8 encoding.
# - * - encoding: utf-8 - * -
five variable amount.
variables: the operation of the temporary intermediate results into memory, then subsequent to a program use tone.
variable amounts of naming rules:
1, a variable amount by the word ⺟ letters, numbers, underscores combinations ⽽ formed
2, use does not start with a number, not less is more full digital
python basic data types What is what type of data? Face the difference we humans can easily distinguish easily the numbers and characters, but the computer does not die, although very strong zoomed big computer, but some ⻆ angle of a separate warranty terms and silly, comes in handy addition to the non-explicitly tell you it is the number 1, "Han" is the text files, otherwise it is not clear difference between points 1 and 'Chinese' is, therefore, in each programming your language and speech ⾥ ri ⼀ will have a data type called East East, in fact, a variety of frequently-used data types into ⾏ trekking with a clear division, you want





















Let ⾏ trekking into the computer numerical computation, you pass it to digital, you want him to deal with processing text files, they pass a string string types to him. Using Python with a number of often
have a variety of data types, today we talk about three kinds of temporary number, string, string, Boolean type (proposition).
8.1 Integer (int)
often ⻅ see the numbers are of type int. Use for ⼩ calculation or large small Comparative zoomed
in on 32-bit machines int ranges: 31 ~ -2 ** 2 ** 31-1, i.e. -2147483648 2147483647 ~
on 64-bit machines int ranges: -2 ** 63 ~ 2 ** 63-1, i.e. -9223372036854775808 ~ 9223372036854775807
enough use you use it. Note that these are integers.
8.2 terminated string (str)
in Python, all use quotes, all string the string
string string can be selectively used with a single and double quotation marks, or three quotation marks, there is no difference even just ⼀ format requires no special marks will not be used with
⽐ such as:
MSG = "My name iS Alex, the I 'm 22 years old! "this requires single or double quotation marks fit.
msg = "" "
Today I want to write the first ⼩ therefore especially verses,
sing my classmate,
you see his black black and black short hair,
like ⼀ a fried chicken ⽑ hair. "
""
want more ⾏ trekking assignment ⼀ a string string, it requires three quotes.
Numeric types are + - * / String string, too?
Only + * terminated string.
# String concatenation string
s1 = 'a'
= S2 'BC'
#Print (S1 + S2)
# * int multiplying STR
name = 'strong'
#Print (* name. 8)
8.3 Boolean (bool), true or false, True, and False
nine. Using user interaction
so use with input () function allows us to interact with computers up
syntax:
content = input (Tips shows information)
individual cases from inside where you can get directly to the contents using the user input
⼗ ten flow control if statement sentence.
you live in ⽣ is not not often encounter a variety of options, such as playing ⽐ discolored color sub-submenus, guess zoomed little big lower, and ⽐ such as selecting ⾛ go that way way home? Python program will
encounter this situation, which uses the if statement Use sentence.
First Time syntax:
IF condition: # quotes is to separate conditions and results.
Results 1. # Four spaces, or a tab key ⼀, this is enough to tell the program full EMPTY this condition
results 2.
If the condition is true (True) YES trekking Results 1, 2 and the results, if the condition is false (False) direct result of 2
second shot two kinds of syntax:
the If Condition:
Results 1
the else:
Results 2
Code 3
Third Syntax:
the If condition 1:
results 1
elif condition 2:
results 2
..
the else:
Results n
fourth syntax (nesting):
the If Condition 1:
Results 1
the If Condition 2:
Results 2
the else:
Results. 3
the else:
Results 4
. ⽆ can be unlimited, but in the actual development nested try an amount not more than three nested
⼗ ten ⼀ I. process control loop -while
in ⽣ life, we encounter things cycle, right? ⽐ songs such as cycling. In the program, but also keep it, and this is an empty statement processes sentence
while.
Analog ⼀ songs about the cycle:
the while True:
Print ( 'We are not the same as not ⼀')
Print ( 'we are all the same ⼀')
Print ( 'what's not is not the same as ⼀')
the while condition:
result
if the condition is true, perform trekking direct result of then determine the condition again until the condition is false. stop stop cycle
that how we ended termination for still circulating it?
The end of the cycle:
1, changing conditions.
2, BREAK
⼗ ten ⼆ two flow control -break and the Continue.
1, BREAK: break out of the cycle of immediate meaning.
2, the Continue: Stop stop this cycle, continue to Perform trekking record the next cycle.
job:
1, use while loop output. 5. 4. 3. 6 2 1. 8. 9 10
2, find all the numbers from 1 to 100 and
3, the output of all the odd 1-100
4, the output of all the even-numbered 1-100 within
5, seeking 1-2 + 3-4 + 5 ... 99 for all numbers and
6, user login Use (three chances weight test)

Guess you like

Origin www.cnblogs.com/Selbst/p/11810364.html