Python learning Day 1-Introduction to installing Hello world, python1-

Source: Internet
Author: User
Tags support microsoft

Python learning Day 1-Introduction to installing Hello world, python1-

Introduction

Python is an object-oriented, interpreted computer programming language, invented by Guido van rosum at the end of 1989, the first Public release was released on July 15, 1991. The Python source code also complies with the GPL (GNU General Public License) Protocol [1]. The Python syntax is concise and clear, and has rich and powerful class 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.

  • Python is an interpreted language:This means there is no compilation link in the development process. Similar to PHP and Perl.

  • Python is an interactive language:This means that you can directly interact and execute your program at a Python prompt.

  • Python is an object-oriented language:This means that Python supports object-oriented style or code encapsulated in the object programming technology.

  • Python is a beginner's language:Python is a great language for beginners. It supports a wide range of application development, from simple text processing to WWW browsers to games.

Install

Python has been ported to many platforms (changed to enable it to work on different platforms ).

You need to download the binary code for your use of the platform, and then install Python.

If the binary code on your platform is unavailable, you need to use the C compiler to manually compile the source code.

The compiled source code has more features and provides more flexibility for python installation.

The following describes how to install Python on different platforms:

Install Python on Unix and Linux platforms:

Follow these steps to install Python on Unix and Linux:

  • Open WEB browser access http://www.python.org/download/

  • Select the source code compressed package for Unix/Linux.

  • Download and decompress the compressed package.

  • If you need to customize some options to modifyModules/Setup

  • Run./Configure script

  • Make

  • Make install

After the above operations are performed, Python will be installed in the/usr/local/bin directory, and the Python library will be installed in the/usr/local/lib/pythonXX and XX Python version numbers for you.

Windows platform Python installation:

Follow these steps to install Python on the Windows platform:

  • Open WEB browser access http://www.python.org/download/

  • In the download list, select the Windows Installation Package in the following format:Python-XYZ.msiFile, XYZ is the version number you want to install.

  • To use the installerPython-XYZ.msiWindows must support Microsoft Installer 2.0. Just save the installation file to your local computer and run it to see if your machine supports MSI. Windows XP and later versions already have MSI, and many old machines can also install MSI.

  • After downloading the package, double-click it to go to the Python Installation Wizard. The installation is very simple. You only need to use the default settings and click "Next" until the installation is complete.

Install Python on MAC:

Recent Macs systems all come with Python environments, but the built-in Python version is the old version, you can view the new version of Python features on MAC by linking the http://www.python.org/download/mac.

Environment variable configuration

Programs and executable files can be stored in many directories, which may not be in the search path that the operating system provides executable files.

Path is stored in the environment variable, which is a named string maintained by the operating system. These variables contain information about available command line interpreters and other programs.

In Unix or Windows, the PATH variable is PATH (UNIX is case sensitive, and Windows is case insensitive ).

In Mac OS, the python installation path is changed during installation. If you need to reference Python in another directory, you must add the Python directory in path.

Set environment variables in Unix/Linux
  • In csh shell:Input

    setenv PATH "$PATH:/usr/local/bin/python"

    , Press "Enter ".

  • In bash shell (Linux ):Input

    export PATH="$PATH:/usr/local/bin/python"

    , Press "Enter ".

  • In sh or ksh shell:Input

    PATH="$PATH:/usr/local/bin/python"

    , Press "Enter ".

Note:/Usr/local/bin/python is the installation directory of Python.

Set environment variables in Windows

Add the Python directory to the environment variable:

  • In the command prompt box (cmd ):Input

    path %path%;C:\Python 

    , Press "Enter ".

Note:C: \ Python is the installation directory of Python

Python Environment Variables

The following are several important environment variables used in Python:

Variable name Description
PYTHONPATH PYTHONPATH is the Python search path. By default, all the import modules are searched for in PYTHONPATH.
PYTHONSTARTUP After Python is started, find the PYTHONSTARTUP environment variable and then execute the Execution Code specified by the variable in this file.
PYTHONCASEOK Adding environment variables of PYTHONCASEOK will make the python import module case insensitive.
PYTHONHOME Search Path for another module. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directory, making it easier to switch between two module libraries.
Run Python

There are three ways to run Python:

1. Interactive Interpreter:

You can enter python in the command line window and start writing Python code in the interactive interpreter.

You can perform python coding on Unix, DOS, or any other system that provides command line or shell.

$ Python # Unix/Linux

Or

Python % # Unix/Linux

Or

C:> python # Windows/DOS

The following are Python command line parameters:

Option Description
-D Display debugging information during parsing
-O Generate optimization code (. pyo file)
-S The location of the Python path is not introduced at startup.
-V Output Python version number
-X The built-in exceptions (for strings only) after MySQL 1.6 are outdated.
-C cmd Run the Python script and use the running result as the cmd string.
File Execute the python script in the given python file.
2. Command Line script

In your application, you can introduce the interpreter to execute the Python script in the command line, as shown below:

$ Python script. py # Unix/Linux

Or

Python % script. py # Unix/Linux

Or

C:> python script. py # Windows/DOS

Note:When executing the script, check whether the script has the executable permission.

3. Integrated Development Environment (IDE: Integrated Development Environment)

You can use the graphical user interface (GUI) environment to write and run Python code. The IDE used on each platform is recommended as follows:

  • Unix:IDLE is the earliest Python IDE on UNIX.

  • Windows:PythonWin is an integrated Python development environment, which is superior to IDE in many aspects.

  • Macintosh:Python Mac can use idle ide, you can download the corresponding mac idle on the website

The first python program:

>>> print 'hello, world'hello, world

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.