Python: Understanding Modules

Source: Internet
Author: User

First, understand the Python module :

  -- What is a function:

A function is a program that implements one or more functions

A module is a program block that implements a class of functions, a script file that contains functions and other statements, with a suffix of ". Py"

By default, the module is stored in c:/python27/lib

-- How to import the module: using import

    

We want to be able to show the value of pi directly, but no.

  

    Now, import the corresponding module name using import, we can get the value of pi   

-- Understanding the sys module

SYS module: modules related to system functions

  

Sys.version--View version information

Sys.executable--The file name that the parser can perform

Sys.getwindowsversion ()--Version information

Second,"*. PYc file": Apython parser-generated binary file after the module is compiled

three,F orm ... import ...

1. Import Module Name: Imports the corresponding module (see one )

2.from. Import function name (function, attribute, etc.): one of the functions that the import module corresponds to

3.from. Import *: Import all functions of the module

  

  

  

Iv. Understanding __name__ Properties : can be used to determine whether the other modules are called

  

  

Is the result of running test.py directly (self-invocation)

  

Is the result of running call.py directly (other module calls)

Five. Custom Module : Non-system comes with the module

    

The Python version used in this article is 2.7.10and the tool is pycharm

Python: Understanding Modules

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.