My introduction to Python

Source: Internet
Author: User

One, Introduction to Python

Python is a computer programming language, all using C language, but easier to learn than C language, easy to read. Python can be used in a number of areas, the overall upward trend, the widespread use of Python to do things like: automated operations , automated testing , Big Data analysis, crawler, Web and so on. so the python foreground is very good.

Two, the type of Python

As we can see, we learn Python rules which are based on Python.

Third, Python environment:

Python installation under 1,windows:

python:https://www.python.org/

Download installation

Configure environment variables after installation is complete, right-click Property points in My Computer advanced settings

Double-click Environment variables

inside the second box find the path double-click

Add the following path to the Python installation; C:\Python27

After adding, make sure that the Python environment is built.

2,linux:

Linux comes with Python and does not have to be installed.

Four: Getting Started with Python

1, how to start and exit the Python interactive environment:

Function key +r appear to run, in the Run box cmd enter, and then in the play Python will go to the interactive environment prompt>>>下,这样就可以使用Python。最后,用exit()退出Python。

2, use a text editor:

In Python's interactive command-line write program, the advantage is that you can get results, the disadvantage is unable to save, so we have to write in the text and then execute. We are on a disk for example on D: we create a new folder to define a name to do the canonical Py_code, the code we write later is placed under this file for easy search.

  那么我们print‘hello,world‘Then, select a directory, for example d:\py_code , save the file as hello.py , you can open the Command Line window, the current directory to switch to the hello.py directory, you can run the program. Remember that you want Python to connect to the path before the file path can be executed.

Five, interpreter

In the text we first need to comment on what interpreter is used to execute the script we write. So we're going to start with the text. Comment: #! /use/bin/env python

Print "Hello,world" so that it can be executed directly.

Note: You need to give hello.py execute permission before execution, chmod 755 hello.py

Six, content encoding

When the Python interpreter loads the code in the. py file, the content is encoded (default Ascill) so there is a second line of comments on the text header #_ *_ coding:utf-8 _*_ This is an issue that cannot be expressed in Chinese. That is, tell the Python interpreter what code to use to execute the source code.

Seven, notes

When the line stares: # is annotated content

Multiline Comment: "" "Annotated Content" ""

Eight, execute script incoming parameter

Python has a large number of modules, which makes developing Python programs very concise. The class library includes three:

    • Python-supplied modules
    • Industry-Open Source modules
    • Modules developed by programmers themselves

Python internally provides a SYS module where SYS.ARGV is used to capture parameters passed in when executing a python script

123456 #!/usr/bin/env python# -*- coding: utf-8 -*- import sys  printsys.argv

Nine, variable

The variable name is: Name, and the value of the variable name is: "World"

Rules for variable definitions:

Variable names can only be any combination of letters, numbers, or underscores

The first character of a variable name cannot be a number

The following keywords cannot be declared as variable names

[' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ' , ' for ', ' from ', ' global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' ret ' Urn ', ' try ', ' while ', ' with ', ' yield ']

My introduction to 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.