The first study of Python

Source: Internet
Author: User

The basic composition and function of computer

The basic components of the computer are: CPU, memory, hard disk, Operation center.

Cpu:

The CPU is the equivalent of the computer's brain, the computing center, the processing of data and the operation of various instructions.

Memory:

Temporarily store a small amount of data for the CPU to perform the operation.

Advantages: Fast reading speed.

Disadvantages: Small capacity, high cost, can only temporarily store data, the power loss data disappears.

Hard disk:

Long-term storage of large amounts of data, the power will not disappear, the computer's long-held data are on the hard disk.

Advantages: Large capacity, low cost, power-off data will not disappear.

Disadvantage: Slow reading speed.

Operating system:

Provision the operation between each hardware.

Common operating systems are: Windows;linux;cenos,mac .....

Python First Knowledge

Python history (citation 1)

The history of Python

The founder of 1.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 ). ( buffer time due to switching problem between python2x and python3x)

2. Current Python main 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 uses the most, and the importance of increasing year by 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
    • Graphics GUI:PYQT, Wxpython,tkinter

2.python history

(1) history

  • 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, -
  • 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 ( year by month, people announced that it will support python 2.7 until 2020 , and reiterates that there will be no 2.8 versions as users may migrate to Python as soon as possible 3.4+ . )
  • Python 3.0-december 3, -
  • 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

(python2.6 and python3.0 for the same year update, python2x updated to 2020, and updated mode and specification gradually to python3x near)

(2) The difference between python2x and 3x

Python: Beautiful, clear and simple.

PYTHON2X: Source code is not standardized, but also chaotic, more repeated codes. Default encoding mode ASCII

Show English: First line: #-*-Encoding:utf-8-*-

Python3x: Re-source code, code specification, beautiful, clear, simple. The default encoding method is Utf-8.

Categories of Python

1. Overall language classification:

Classification:

1. Compiled type

Compile the code all at once into a two-tier system and run it again.

Advantages: High execution efficiency.

Disadvantage: Development efficiency is slow, can not cross the platform.

Representative language: C.

2. Explanatory

The code is interpreted line by row, interpreted as binary, and then run.

Advantages: The development of high efficiency, third-party libraries, can cross-platform.

Disadvantage: Low execution efficiency.

Representative language: Python.

2. Various types of language representatives:

Compiler type: c;c++;go;swift;object-c;pascal.

Explanatory type: Javascript;python;ruby;php;perl;erlang.

Mixed type: java;c#.

Advantages and disadvantages of Python

Advantages

1.Python positioning is "elegant", "clear", "simple", so the Python program is always easy to understand , beginners learn python, not only easy to get started, and in the future, can write those very very complex programs.

2. The development efficiency is very high , Python has a very powerful third-party library, basically you want to achieve any function through the computer, the Python official library has the corresponding module to support, directly download the call, on the basis of the base library to develop, greatly reduce the development cycle, Avoid making wheels repeatedly.

3. high-level language ———— when you write programs in the Python language, you don't have to consider the underlying details such as how to manage the memory used by your program (memory usage is high and memory consumption is low)

4. portability ———— because of its open source nature, Python has been ported on many platforms (modified to make it work on different platforms). If you are careful to avoid using system-dependent features, all your Python programs can run on almost any system platform on the market without modification

5. Extensibility ———— If you need a piece of your critical code to run faster or you want some algorithms to be private, you can write some of your programs in C or C + + and then use them in your Python program.

6. embeddable ———— You can embed python in your C/C + + program to provide scripting functionality to your program users.

Disadvantages:

1. Slow , Python is running faster than the C language is really much slower, and slower than Java, so this is also a lot of so-called Daniel disdain to use Python's main reason, but in fact, this refers to the slow speed in most cases the user is not directly aware of , must rely on the test tools to reflect, such as you use C a program to spend 0.01s, with Python is 0.1s, so c directly than Python 10 times times faster, is very exaggerated, but you can not directly perceive through the naked eye, Because a normal person can perceive the smallest unit of time is 0.15-0.4s around, haha. In fact, in most cases python has been fully able to meet your requirements for the speed of the program, unless you want to write to the speed of the most demanding search engine, in this case, of course, it is recommended that you use C to achieve.

2. The code cannot be encrypted , because Python is an explanatory language, its source code is stored in the form of a name, but I do not think this is a disadvantage, if your project requires that the source codes must be encrypted, then you should not use Python in the beginning to implement.

3. threads do not take advantage of multi-CPU issues , which is one of the most common drawbacks of Python, the Gil, the Global Interpreter lock (interpreter lock), is a computer programming language interpreter for the tool for synchronizing threads so that only one thread executes at any moment, andthe Python thread is the native thread of the operating system. On Linux for Pthread, on Windows for win thread, the execution of threads is fully dispatched by the operating system. A Python interpreter process has a main thread and the execution thread for multiple user programs. Multi-threaded parallel execution is prohibited even on multicore CPU platforms due to the existence of the Gil. A compromise solution to this problem is discussed in more detail later in the Threads and Processes section.

when we write Python code, we get a text file that contains Python code with an extension of. py. To run the code, you need the Python interpreter to execute the. py file.

as the entire The Python language is open source from spec to interpreter, so in theory anyone can write a Python interpreter to execute Python code (which is difficult, of course) if the level is high enough. In fact, there are a number of Python interpreters.

variables

Variables: Store the calculated intermediate results for subsequent code use.

Rules for variable settings:

1. Must be a letter, number, underline any combination.

2. Cannot be the beginning of a number.

3. Cannot be a keyword in python.

4. The variable cannot be in Chinese,

5. Variables cannot be too long.

6. The variable has a descriptive type.

Constant

Constant: The amount that has remained constant. The default is all uppercase variables are constants.

Comments

Help you understand other people's code and recall your own code.

Single-line Comment: #被注释内容, multiline comment "" is the Content "" "" "is the Content" ""

Boolean value (logical judgment)

Boolean (bool) only two values True (True) False (false), mainly used for logical judgments.

The first letter of the Boolean value is capitalized.

Type (data attribute judgment)

Determine what data type the decision object belongs to

Name = input (' Please enter your name: ')
Age = input (' Please enter your ages: ')
Print (Name,age,type (name), type (age))

Input (content interaction)

Input is the most basic content interaction and is primarily used to make the consumer input primary and the input object to be a string.

Name = input (' Please enter your name: ')
Age = input (' Please enter your ages: ')
Print (Name,age,type (name), type (age))

if (IF)

1. Single write:

If space condition: (colon)

(four spaces (tab)) results

that is: if Xxxx

then xxxx

Print (111)
If 3 > 2:
Print (666)
Print (333)
2.if Mate Else (if: Otherwise.. )
If Else
Name = input (' Please enter your name: ')
If name = = ' Rajah ':
Print (' Old iron, no problem ')
Else
Print (' ill-treated ... ')
3.if Mate Elif (if: Or... Or... )

If Elif ...
num = Int (input (' Please enter your choice: '))  # str---> int str all consist of numbers
if num = = 4:
Print (' Lunch me Please ')
elif num = = 5:
Print (' Dinner me Please ')
elif num = = 6:
Print (' Big health, walk up ')
3.if Mate Elif...else (if: Or... Otherwise... )
If elif ... else

num = Int (input (' Please enter your choice: ')) # str---> int str all consist of numbers
if num = = 4:
Print (' Lunch me Please ')
elif num = = 5:
Print (' Dinner me Please ')
elif num = = 6:
Print (' Big health, walk up ')
Else
Print (' Give you a chance to catch ... ')


Nesting
Frequently asked questions, according to Python read rules, from top to bottom, the problem leads to the problem, the final answer, but the top of the unfinished instruction to go directly to the result.
NUM1 = input (' Please enter a number ')
if num1 = = ' 3 ':
num2 = input (' Please enter a number: ')
if num2 = = ' 5 ':
Print (' This all can guess right ')
Else
Print (' Keep trying ')

score = Int (input ("Enter score:"))
If score > 100:
Print ("I rub, the highest score is only 100 ...")
Elif Score >= 80:
Print ("B")
Elif Score >= 90:
Print ("A")
Elif Score >= 60:
Print ("C")
Elif Score >= 40:
Print ("D")
Else
Print ("Too stupid ... E ")

While condition:
Results
Frequently asked questions, according to Python read rules, from top to bottom, the problem leads to the problem, the final answer, but the top of the unfinished instruction to go directly to the result.

Note Vocabulary :

while (loop) break (terminate Loop) continue (terminates this loop)
Print (print) True (true) False (false) if (if, assuming) else (otherwise)
Elif (or) Input (output-dialog)%s d (format) type (test nature)

The first study of Python

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.