1th Day of Python learning-introduction and Getting Started

Source: Internet
Author: User

Objective

Why use Python

Python is a highly efficient language. A program written in Python contains less code than many other languages that implement the same functionality. Python's syntax is simple, easy to use, and code written in Python is easier to read, debug, and extend.

Python uses a lot more fields. Python applications include: Cloud computing, AI, big Data, finance, Web development, network programming, scientific computing, GUI graphics development, automated operations, game development, solving business problems, and developing internal companies for all kinds of interesting companies.

1. Introduction to Python

The founder of Python is Guido van Rossum;python is an open source, interpretive language, dynamic language, strongly typed definition language (type-safe language), Python is a dynamic explanatory strong type definition language.

1.1 Python application areas

(1) Cloud computing. Python is the most popular language for cloud computing and is typically used by OpenStack.

(2) Artificial intelligence . Artificial Intelligence, developed based on big data analytics and deep learning, is inherently unable to leave Python support, and the world's best AI learning framework, such as Google's Ransorflow, Facebook's Pytorch and the open source community's neural network library Karas are implemented in Python, and even Microsoft's CNTK (Cognitive toolkit) fully supports Python, and Microsoft's Vscode has supported Python as a first-level language.

(3) Big data. Python's biggest feature relative to other explanatory languages is its vast and active scientific computing ecosystem, which has a fairly complete and excellent library of data analysis, interaction, and visualization (Python data analysis stack: Numpy Pandas Scipy matplotlip Ipython), And also formed its own unique scientific computing for the Python distribution version anaconda, and these years have been rapid evolution and refinement, the traditional data analysis language such as R MATLAB SAS Stata formed a very strong alternative.

(4) Web development . Python is much more scalable than Php\ruby's modular design, and over the years has created a number of excellent web development frameworks and iterations, such as the current excellent full-stack Django, framework flask, all inherit Python's simple, clear style, The development of high efficiency, easy maintenance, and the integration of automation operations, Python has become an automated operation and maintenance platform in the field of fact standards; many large sites are Python development, Youtube, Dropbox, watercress.

(5) System operation and maintenance . Python is very close to the operating system and is managed, and currently all Linux distributions have Python, and there are a number of modules available for the relevant management functions in Linux, such as the current mainstream Automation configuration management tool: Saltstack Ansible (currently Redhat). Currently, in almost all internet companies, the standard for automated operations is python+django/flask, and OpenStack, which is already a de facto standard in virtualization management, is Python, so Python is a must-have skill for all operations personnel.

(6) Finance . Quantitative trading, financial analysis, in the field of financial engineering, Python is not only used, and used the most, but also 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

(7) Graphical GUI. PyQT, Wxpython,tkinter.

Advantages and disadvantages of 1.2 python

1.2.1 Pyhon Advantages

(1) Good platform compatibility, can be run in any environment, provided that the interpreter (virtual machine) is installed. Flexible, modify the code when the direct modification can be quickly deployed, without downtime maintenance.

(2) Once a variable is assigned a data type, it is always the data type if it is not cast. For example: If you define an integer variable A, the program simply cannot treat a as a string type. A strongly typed definition language is a type-safe language.

(3) easy to learn. Especially suitable for beginners to learn python, not only easy to get started, but also in the future, you can write those very very complex programs.

(4) The development efficiency is 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, to avoid repeating the wheel.

(5) Advanced language. When you write programs in the Python language, you do not have to consider the underlying details such as how to manage the memory used by your program.

(6) Scalability is good. 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.

(7) Strong embedding ability. You can embed python in your C/C + + program to provide scripting functionality to your program users.

1.2.2 Python drawbacks

(1) Each time you run the time to explain, performance is not as good as the compiled language.

(2) Slow speed. Python runs at a much slower pace than the C language and is slower than Java, so this is the main reason why so many so-called Daniel disdain to use Python, but in fact, this refers to the slow running speed in most cases the user is not directly aware of, must rely on testing tools to reflect , such as you use C a program to spend 0.01s, with Python is 0.1s, so C language directly than Python 10 times times faster, is very exaggerated, but you can not directly through the naked eye perception, 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.

(3) 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.

(4) Multithreading problem. This is the most common disadvantage of Python, Gil is the global interpreter lock (interpreter lock), is the computer programming language interpreter used to synchronize threading tools, so that at any moment only one thread in the execution, 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.

1.3 Python interpreter

When we write the Python code, we get a text file that contains the Python code with a. py extension. To run the code, you need the Python interpreter to execute the. py file. 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.

(1) CPython. When we downloaded and installed Python 2.7 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 Python at the command line is the start of 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 uses >>> as a prompt, while Ipython uses in [ordinal]: 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.

installation of 1.4 Python

Official website: https://www.python.org/downloads
Official documents: https://docs.python.org/2.7/or https://docs.python.org/3.6/or https://docs.python.org/3.7/, etc.

1.4.1 installing Python in Windows systems

(1) Download the installation package. Download the version of Python that needs to be installed on the website and the latest version is Python3.

(2) Click Execute file to install. You can customize the installation directory, and the rest is next.

(3) Configure environment variables. In order to run Python in the cmd window, configure the Python installation path to the path of the environment variable. For example: Your Python installed D:\Python36, then add D:\Python36 to path, and use a semicolon ";" Set it to the value of the original path.

(4) Execute Python in the cmd window. If a Python prompt (>>>) appears, Windows finds the version of Python you just installed.

Note: If "Add Python to PATH" is checked during installation, you do not need to manually reconfigure environment variables.

1.4.2 Write your first Python program

Whenever we learn a programming language, it seems that "Hello world" is our first small program to get started. Let's experience the introductory ceremony together.

Since Python2 and Python3 have some grammatical differences, so if you are installing Python2, then in the cmd window enter Python and enter into the Python interactive, after the prompt (>>>) input: print "Hello World! ", as shown in:

If you are installing Python3, then enter Python in the cmd window, return to the Python interactive, and enter after the prompt (>>>): Print ("Hello world!") as shown in:

The above is to run the Python program at the terminal, then how to save the python code?

Each programming language has its own suffix identifier, Python is no exception, and Python's program suffix is ". py". For example, we will save the code executed on Python3 as: hello_world.py file, and save it to the H drive, then enter the cmd window, enter the H disk, execute the file with the command Python hello_world.py, as shown in:

1.4.3 Installing a text editor

Geany is a simple text editor: It's easy to install, allows you to run almost any program (without having to go through a terminal), use different colors to display code to highlight code syntax, and run code in a terminal window so you can get used to the terminal.

: https://www.geany.org/Download/Releases

The default installation is sufficient.

1.4.4 Pycharm

Pycharm is a Python IDE with a complete set of tools to help users improve their efficiency when developing with the Python language, such as debugging, syntax highlighting, project management, code jumps, smart tips, AutoComplete, unit tests, versioning. In addition, the IDE provides advanced features to support professional web development under the Django framework.

Pycharm has a Community edition and Pro version, and the Pro version is paid for.

: https://www.jetbrains.com/pycharm/

Install, select a custom path, or install it by default.

Introduction to the use of Pycharm: http://blog.csdn.net/msda/article/details/38705525

1th Day of Python learning-introduction and Getting Started

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.