Python Learning series----Fifth module

Source: Internet
Author: User

5.1 How to introduce modules

Using the keyword import in Python to introduce a module, such as referencing module math, can be introduced with import math at the very beginning of the file. When you call a function in the math module, you must refer to this:

Module name. function name

  

  

Sometimes we just need to use a function in the module, we just need to introduce the function, at this point we can pass the statement

From Module name Import function name 1, function name 2 ....

  

5.2 How to define your own modules

In Python, each Python file can be used as a module whose name is the name of the file.

For example, there is a file test.py that defines the function add in test.py:

#test. Pydef Add (b):    return a+b

In other files, you can import test first, then call it through Test.add (A, B), and of course, by using the From test import Add. (Example from http://www.cnblogs.com/dolphin0520/archive/2013/03/19/2969152.html)

Python Learning series----Fifth module

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.