Python BASICS (1), python BASICS (

Source: Internet
Author: User

Python BASICS (1), python BASICS (
I. Python Environment

Windows:

1. Download the installation package https://www.python.org/downloads/2?install the default installation path: C: \ python273. Configure the environment variable [Right-click the computer] -- "[attribute] --" [advanced system settings] -- "[advanced] --" [environment variable] -- "[in the second content find a line with the variable name Path in the box, double-click] --> [append the Python installation directory to the variable value, and separate it with;.] example: the original value; C: \ python27; remember that there is a semicolon before it.

Linux:

No installation required. original Python environment ps: If 2.6 is provided, update to 2.7.

Ii. Update python

Windows:

Uninstall and reinstall

Linux:

Linux yum dependency comes with Python. To prevent errors, the update here is actually to install another Python! Check the default Python version python-V 1. install gcc to compile the Python source code yum install gcc2. Download the source code package, https://www.python.org/ftp/python/3#decompress the package and import it to the source code file 4. /configure make all make install5, view version/usr/local/bin/python2.7-V6, modify the default Python version mv/usr/bin/python/usr/bin/python2.6 ln-s /usr/local/bin/python2.7/usr/bin/python7 to prevent yum execution exceptions, modify the Python version vi/usr/bin/yum used by yum to set the header #! /Usr/bin/python #! /Usr/bin/python2.6

  

Python Basics

1. The first python file in life

Vim hell. py (create)

#!/usr/bin/env python#-*- coding:utf-8 -*-print "hello,world"

Run:

Python hello. py can be used or the execution permission is added: chmod 755 hello. py./hello. py

Explanation:

1 #! // Usr/bin/env python # The reason why the script starts with env is that the script interpreter may be installed in different directories in linux, env can be searched in the PATH directory of the system. At the same time, env also specifies some system environment variables. Env is: envirnment environment variable) 2 #-*-coding: UTF-8-*-specify the encoding type as UTF-8 (for more information, see)

 

Ii. Differences between python versions:

  • Comparison between 2. x and 3. x:
I. print differences 2.x: print "" or print () can be printed normally. 3.x: only print () can be printed. Otherwise, SyntaxError 2 and input raw_inut differences may occur. 2.x: input: outputs the native data type. If the input value is of any type, the output type is raw_input. All outputs are in string format. 3.x: The raw_input method is canceled. Only input () can be used () iii. class difference 2.x: new classes and classic classes are supported. When new classes are used, the class inheritance sequence will affect the final inheritance result 3.x: new classes must be used, solved the inheritance order between classes. 4./2.x: for example, 1/2, 2. the output value of x is 0 3.x, for example, 1/2 3. x outputs 0.5

  

III. Basic python Data Types

Int signed integer, such as: 111, 111,-1,-..., 2. x in the range of-2 ** 31 ~ Between 2 ** 31-1, depending on the operating system, will not be smaller than this range float floating point type, such as: 1.11.1.111,-1.111... str string, such as 'hello', 'python', '1', 'string '..., note that the string must be enclosed by quotation marks ('') or double quotation marks (" "). boolean type has only two values. True: True False: False. Any non-zero data type, the result is true. If the result is int 0, the Falselong type exists only 2. version x. The value range is infinite, depending on the available virtual memory complex plural, such as: 3 tuples (tuple) such as ('A', 'Hello', 'python ', '1') list (list) such as ['A', 'Hello', 'python', '1'] Dictionary (dict) such as {'name': 'zcy ', 'age': 25, 'job', 'it '}

 

 

Iv. python comments

Python can be annotated in two ways. One is a single line comment. You can add the # symbol before the statement. You can also use multiple lines of comment, use three consecutive single quotes to add two sides to the content range to be annotated, or use three consecutive double quotes. For example:

''' Here is

Note

'''

"""

Here too

Note

"""

V. pyc File

When you run the Python code. py file, a file with the same name is automatically generated during execution. pyc file, which is the bytecode generated after the Python interpreter is compiled.

Vi. input parameters by script

Python has a large number of modules, making it very simple to develop Python programs. There are three class libraries:

  • Python internal modules
  • Open-source modules in the industry
  • Modules developed by programmers themselves

Python provides a sys module, where sys. argv is used to capture the parameters passed in when the python script is executed.

#!/usr/bin/env python#-*- coding:utf-8 -*- import sys print("sys.argv")

VII. Variables

  • Variable names can only be any combination of letters, numbers, or underscores
  • The first character of the variable name cannot be a number.
  • The following keywords cannot be declared as variable names
  • ['And', 'as', 'assert ', 'Break', 'class', 'contine', 'def', 'del ', 'elif ', 'else', 'Got t', 'exec ', 'Finally', 'for ', 'from', 'global', 'if', 'import', 'in ', 'Is ', 'lambda', 'not ',' or ', 'pass', 'print', 'raise ', 'Return', 'try', 'while ', 'with', 'yield ']

3. Variable assignment

A = 5 print (id (a) # print the result as 140723441682376

  

 

 

 

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.