Getting started with Python's Road of DevOps development

Source: Internet
Author: User

About Python

The founder of Python is Guido van Rossum (Guido van Rossum). During the Christmas of 1989, Guido van Rossum to spend time in Amsterdam, determined to develop a new script interpreter, as an inheritance of the ABC language. As we all know, the concept of the current full stack engineer is very fire, and Python is a full stack of development language, so if you can learn python, then the front-end, back-end, testing, big data analysis, crawler, artificial intelligence, embedded, and so on, you can be competent.

About the philosophy of Python: Python advocates elegance, clarity, and simplicity, for example, if the same functionality you write in C + + may write 100 lines of code, and if you write in Python you might just have 20 lines of code, The same is true if there are several solutions to a problem, but Python is implemented in the simplest way possible. So Python solves the problem with the simplest, most elegant, and most definitive way.

The following is the latest Tiobe leaderboard, Python overtaking C # occupy the four, Python advocating beautiful, clear, simple, is a good and widely used language.

Statistics Address:https://www.tiobe.com/tiobe-index/

By the visible, python overall is an upward trend, reflecting the Python application is more and more widespread and also gradually get recognition in the industry!

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 Web sites are developed for Python, Youtube, Dropbox, watercress, 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 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
    • graphical GUI: PyQT, Wxpython,tkinter

Python is used in some companies:

    • Google : Google App Engine, code.google.com, Google Earth, Google crawlers, Google ads and other projects are heavily used in Python development
    • CIA: The US CIA website was developed in Python.
    • NASA: NASA uses Python for data analysis and computation
    • YouTube: The world's largest video site, YouTube, is developed in Python
    • Dropbox: The largest online cloud storage site in the United States, all implemented in Python, each day the site handles 1 billion files upload and download
    • Instagram: The largest image-sharing social network in the United States, with more than 30 million photos shared every day, all developed in Python
    • Facebook: A large number of base libraries are implemented in Python
    • Redhat: The Yum Package management tool in the world's most popular Linux distribution is developed in Python
    • watercress : Almost all of the company's business is developed through Python

Advantages and disadvantages of Python:

Advantages

    1. Python's positioning is "elegant", "clear", "simple", so the Python program looks always easy to understand, beginners learn python, not only easy to get started, but also in the future, you can write those very very complex programs.
    2. 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 modules 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
    4. portability ———— because of its open source nature, Python has been ported to many 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. Scalability ———— 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 into your C + + program to provide scripting functionality to your program users.

Disadvantages

    1. Slow , Python runs faster than the C language, and slower than Java, so this is the main reason why many so-called Daniel disdain to use Python, but in fact, this refers to the speed of slow in most cases the user is not directly aware of, Must rely on the use of testing tools to reflect, such as you use C a program to spend 0.01s, 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. code can not 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 are not able to take advantage of multi-CPU problems , which is one of the most common drawbacks of Python, the Gil, the Global Interpreter lock (interpreter lock), is the tool that the computer programming language interpreter uses to synchronize threads. So that at any moment only one thread is executing, the 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.

Categories of Python interpreter:

Since the entire Python language is open source from spec to interpreter, it is theoretically possible for anyone to write a Python interpreter to execute Python code (which is difficult, of course) as long as the level is high enough. In fact, there are a number of Python interpreters.

CPython

When we downloaded and installed Python 3 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.

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.

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.

Jython

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

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.

Linux under compile and install Python:

wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgztar -xzvf python-3.6. 5 . TGZCD Python-3.6. 5/. /configure=/usr/local/python3 make make Altinstall

One, variable & character encoding variables

Constants: We're all capitalized on the conventions.

1. Variable declaration:

    1. Python saves all data as a Memory object
    2. In Python, a variable is actually a reference to a Memory object
    3. Dynamic type: At any point in time, an object reference can re-reference a different object (which can be a different data type), as long as it is needed. Built-in function type () returns the data type of a given data item
    4. "=" is used to bind a variable name to an object in memory: If the object implementation exists, it is bound directly; otherwise, the referenced object is created by "=", and the variable name is also an object that has memory, such as: Name= ' Jerry ', name this pointer to Jerry,name= ' Tom ' , name is the pointer to Tom, but Jerry is still in memory, just not being pointed to by the variable name, and will be recycled by the garbage collector at some point, and Java is a bit like. When Test= ' Jerry ', the two variable names, test and name, point to the same address as the memory. ID (test), ID (name), variable name is a memory-referenced identity or symbol.

2. Rules for variable definitions:

    1. Variable names can only be any combination of letters, numbers, or underscores
    2. The first character of a variable name cannot be a number
    3. The following keywords cannot be declared as variable names

[' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' Global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' wit ' h ', ' yield ']

# View by import keyword

Import keyword
Print (keyword.kwlist)

3. The best way to name variables:

    1. Use underscore ' _ ' as a connection, such as Name_variables
    2. Use case, called Hump method, such as Namevariables,namevariables

Note: Do not mix two types of naming, as long as you like

4. Variable Naming conventions:

      1. Variable names (_x) that begin with a single underscore are not imported by the From module import * statement
      2. Variable names (__x) that start with two underscores but end without underscores are local variables of the class
      3. Variable names (__x__) that have double underscores before and after are system-defined variable names and have special meanings for Python interpreters
      4. In interactive mode, the variable name "_" is used to save the result of the last expression

declaring Variables

" Lyshark "

Assigning values to variables

" Lyshark "  = nameprint"lyshark"

character encoding

1. ASCII

ASCII (American Standard Code for Information interchange, United States Standards Information Interchange Code) is a set of computer coding systems based on the Latin alphabet, mainly used to display modern English and other Western European languages, which can be used up to 8 Bit to represent (one byte), that is: 2**8 = 256-1, so the ASCII code can only represent 255 symbols, and the python2.x interpreter is ASCII encoded by default.

2. Unicode

Unicode (Uniform Code, universal Code, single code) is a character encoding used on a computer. Unicode is created to address the limitations of the traditional character encoding scheme, which sets a uniform and unique binary encoding for each character in each language, which specifies that all characters and symbols are represented at least by 16 bits (2 bytes), i.e.: 2 **16 = 65536, note: Here is a minimum of 2 bytes, perhaps more, such as Chinese characters need 3 bytes, the python3.x interpreter default is Unicode encoding.

3, UTF-8

  is the compression and optimization of Unicode encoding, he no longer uses a minimum of 2 bytes, but all the characters and symbols are dynamically categorized: the contents of the ASCII code is saved with 1 bytes, the characters in Europe are saved with 2 bytes, Chinese characters are saved with 3 bytes ...

4, Gb2312,big5

To deal with Chinese characters, programmers designed GB2312 for Simplified Chinese and big5 for traditional Chinese.

GB2312 (1980) contains a total of 7,445 characters, including 6,763 Kanji and 682 other symbols. The inner code range of the Chinese character area is high byte from B0-f7, low byte from A1-fe, occupy code bit is 72*94=6768. 5 of these seats are d7fa-d7fe.

GB2312 supports too few Chinese characters. The 1995 Chinese character extension specification GBK1.0 contains 21,886 symbols, which are divided into Chinese characters and graphic symbol areas. The Chinese character area consists of 21,003 characters. The 2000 GB18030 is the official national standard for replacing GBK1.0. The standard contains 27,484 Chinese characters, as well as Tibetan, Mongolian, Uyghur and other major minority characters. Now the PC platform must support GB18030, the embedded products are not required. So mobile phones, MP3 generally only support GB2312.

From ASCII, GB2312, GBK to GB18030, these coding methods are backwards compatible, meaning that the same character always has the same encoding in these scenarios, and the latter standard supports more characters. In these codes, English and Chinese can be handled in a unified manner. The method of distinguishing Chinese encoding is that the highest bit of high byte is not 0. According to the programmer, GB2312, GBK, and GB18030 belong to the double-byte character set (DBCS).

Error: ASCII code cannot be expressed in Chinese

# !/usr/bin/env python  Print (" Hello, World ")

Correction: It should be shown to tell the Python interpreter what code to use to execute the source code, i.e.:

# !/usr/bin/env python # -*-coding:utf-8-*-  Print (" Hello, World ")

Getting started with Python's Road of DevOps development

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.