Python-learn Note (3)

Source: Internet
Author: User

The Python module

A package is a folder, and a package can have multiple levels;

modules are xxx.py files, you can create your own modules, and import them, the module name is the same as the name of the file;

Python imports a module using the import statement.

Import Math
Print math.sqrt (+) # = 4

Only a few functions of the math module that you want to import

From math import ceil, floor
Print Ceil (3.7) # = 4.0
Print floor (3.7) # = 3.0

# import all definitions from the module
# Warning: deprecated
From Math Import *

Using the From...import import function Sometimes causes conflicts of the same name. At this point, you can give the function an " alias" to avoid conflicts ;

From math import logfrom logging import log as Logger   # logging log now becomes Loggerprint log (   s) # called the lo of math Glogger (' Import from logging ')   # called the log of logging  

# You can also see what properties and methods are in the module using the Dir method
Import Math
Dir (Math)

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.