Python introduction,

Source: Internet
Author: User

Python introduction,
I. Programming Language types

The development of programming language has gone through

# Machine language: directly use binary programming to directly operate the hardware. # Assembly language: it is also a machine-oriented low-level programming language. It replaces binary programming with abbreviated English identifiers, but it is still directly operating hardware. # Advanced language: it is a machine-independent, process-oriented or object-oriented language. It uses human characters to write programs and shields hardware operations.

A high-level language is closer to a human language. Therefore, it must be translated into binary data that can be understood by a computer before it can be executed:

# Compiler type (requires a compiler): for example, C/C ++, the execution speed is fast and debugging is troublesome; # interpreter type (requires interpreter): for example, python, the execution speed is slow, simple debugging. # The two can be compared to preparing a table to eat, and the other is to eat hot pot (while cooking, while eating, the efficiency is slow)

Summary:

Machine language # The advantage is that the execution speed is fast and the memory usage is small # The disadvantage is complexity, low development efficiency, and poor readability, poor portability assembly language # Fast execution speed # low development efficiency and complex advanced languages # Fast execution speed of compiled languages without dependency on the Language Environment, but poor cross-platform # The explanatory language has good cross-platform performance and portability, but the execution speed is slow and relies on the interpreter for running.
II. Introduction to python

Python is an object-oriented interpreted computer programming language. It was invented in 1989 by the Dutch Guido van rosum. The first public release was released in 1991.

Python has rich and powerful libraries. It is often called the glue language, and can easily connect various modules (especially C/C ++) made in other languages. A common application scenario is to use Python to quickly generate a prototype of a program (sometimes even the final interface of the Program) and then have a special requirement on it, rewrite with a more appropriate language. For example, if the graphic rendering module in 3D games has high performance requirements, you can rewrite it with C/C ++ and encapsulate it as an extension class library that can be called by Python. Note that you may need to consider Platform issues when using the extended class library, and some may not provide cross-platform implementation.

Main application fields of python

#1. WEB development-the most popular Python web framework Django, supporting asynchronous and high-concurrency Tornado frameworks, short and concise flask, bottle, django official slogans define Django as the framework for perfectionist with deadlines (to the effect of being an efficient web framework developed for the perfectionist) #2. network Programming-supports High-concurrency Twisted network framework. asyncio introduced by py3 makes asynchronous programming very simple #3. crawler-in the crawling field, Python is almost dominant. Scrapy \ Request \ BeautifuSoap \ urllib and so on. What do you want to crawl? #4. cloud computing-currently the most popular and well-known cloud computing framework is OpenStack. The current popularity of Python is largely due to cloud computing #5. artificial intelligence-who will become the first development language in the AI and Big Data age? This is an issue that does not need to be discussed. If Matlab, Scala, R, Java, and Python had their own opportunities three years ago, and the situation was still unclear, the trend had been quite clear three years later, especially after Facebook opened up PyTorch, as the leading language of the AI era, Python is basically established. The suspense in the future is only who can sit down and take the lead. #6. Automated O & M-ask every O & M personnel in China what language must the O & M personnel speak? 10 people believe that they will give you the same answer, whose name is Python #7. financial analysis-I was in the financial industry. In the past 10 years, many analysis programs and high-frequency transaction software written by our company were using Python. Up to now, python is the most widely used language in the financial analysis and quantitative trading field #8. scientific Computation-you know, since, NASA has been using Python extensively for various complex scientific computation. With the development of NumPy, SciPy, Matplotlib, Enthought librarys, and many other libraries, python is more and more suitable for scientific computing and high-quality 2D and 3D images. Compared with Matlab, the most popular commercial software in the field of scientific computing, Python is a common programming language, which is more widely used than Matlab's scripting language #9. game Development-Python also has many applications in online game development. Compared with Lua or C ++, Python has higher abstract capabilities than Lua, and can describe game business logic with less code. Compared with Lua, Python is more suitable as a Host language, that is, the entry point of the program will be better at the end of Python, and then write some extensions with C/C ++ when necessary. Python is very suitable for writing more than 10 thousand lines of projects, and can well control the scale of online game projects within 0.1 million lines of code. As far as I know, the well-known game <civilization> is written in Python.

Python type

Now we know that Python is an interpreted language. To run the code, it must be executed through the interpreter, the interpreter of Python can also be seen as a program (which of the following languages is not important to the translation lawsuit). What languages is this program developed? How many languages are there? What? Python has several interpreter types, which are developed based on different languages. Each interpreter has different features, but can run our Python code normally. For details, see # CPython: CPython is the most widely used and widely used Python interpreter. This tutorial is based on CPython. After downloading and installing Python 2.7 from the official Python website, we directly obtained an official version of the interpreter CPython. This interpreter is developed in C language, so it is called CPython. Running python in the command line is to start the CPython interpreter. # IPythonIPython is an interactive interpreter based on CPython. That is to say, IPython only enhances the interaction mode, but the function of executing Python code is the same as that of CPython. For example, although many Chinese browsers have different appearances, the kernel actually calls IE. CPython uses >>> as the prompt, while IPython uses In [serial number]: As the prompt. # PyPyPyPy is another Python interpreter whose goal is the execution speed. PyPy uses JIT technology to dynamically compile Python code (note that it is not an explanation), so it can significantly improve the execution speed of Python code. Most Python code can be run in PyPy, but PyPy and CPython are somewhat different, which leads to different results for the same Python code to be executed in two interpreters. If your code is to be executed in PyPy, you need to understand the differences between PyPy and CPython. # JythonJython is a Python interpreter running on the Java platform. You can directly compile Python code into Java bytecode for execution. # IronPythonIronPython is similar to Jython, but IronPython is a Python interpreter running on the Microsoft. Net platform. It can directly compile Python code into. Net bytecode.

 

Iii. python Basics

First python Program

#! /Usr/bin/env python # interpreter path #-*-coding: utf8-*-# encoding method print ('Hello World ')

 

Two execution methods

# Enter the interaction mode of the interpreter: debugging is convenient, real-time input and execution results are obtained, but the Code cannot be saved # script file mode (notepad ++): code can be permanently saved

Note: The python interpreter execution Program is an interpreter execution, that is, opening the file to read the content without specifying the file suffix, which is usually defined as the end of. py for easy differentiation.

Iv. Variables

What is a variable?

# Variables are the amount that can be changed during the program running, "change" is a change, and "amount" is a measure of the status.

 

Variable naming rules

# Variable names can only be any combination of letters, numbers, and underscores # the first character of variable names cannot be numbers # variable names cannot be keywords 'and', 'as ', 'assert ', 'Break', 'class', 'contine', 'def', 'del ', 'elif', 'else', 'example t', 'exec ', 'Finally ', 'for', 'from', 'global', 'if', 'import', 'in', 'is, 'lambda, 'not ', 'or', 'pass', 'print ', 'raise', 'Return ', 'try', 'while ', 'with ', 'yield '# It is best not to repeat the built-in things in python

 

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.