Python's modules and packages

Source: Internet
Author: User

First, the module

We've learned a lot of modules before, and today we'll take a look at how they're used.

1.import

First, customize a module my_moudle.py, that is, the file name is My_moudle

Print('From the my_moudle.py') Money=1000defread1 ():Print('My_moudle->read1->money', Money)defread2 ():Print('My_moudle->read2 calling Read1') Read1 ()defChange ():Global Money Money=0
My_moudle Module

Import statements can be used anywhere in the program, and for the same module is import multiple times, in order to prevent you to repeat the import, Python optimization means: The first import after the module name loaded into memory, Subsequent import statements only add a reference to a Module object that has already loaded large memory, and the statements within the module are not re-executed. As shown below:

Python's modules and packages

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.