Python Learning Notes: the introduction of modules in Python

Source: Internet
Author: User

in thePythonDevelopment (http://www.maiziedu.com/course/python-px/) using the Keyword import to introduce a module, It is similar to the include header file in C + + . For example, to reference the module math, you can use import math to introduce itat the very beginning of the file . when you call a function in the math module, you must refer to this , see the code for details:

>>>improt Math

>>> Math . Sin (0)

To import your own modules:

#hello. Pyprint "Hello world!"

Save the above file under c:/python :

Import SYS

Sys.path. Append (' C:/python ')

>>> Import Hello

Hello world!

Remember to import only once :

>>> Import Hellohello world!

>>> import hello# empty

Modules are used to define functions:

#hello2. Pydef Hello ():

print "Hello, world!"

>>> Import Hello2

>>>hello2.hello ()

Hello, world!.

Here are some miscellaneous:

Package  
In order to better organize the modules, they can be grouped, that is, packages.

Import contants Print contants. PI

Help

>>>help (copy. Copy )


Python Learning Notes: the introduction of modules in 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.