Advanced first Lesson Python module introduction

Source: Internet
Author: User

As we said before, Python has been free and open since it was born. Today, a large number of modules have been created. So here's the question, what's the module?

For Python, a module is a collection of several features.

A module has its own properties, just like a person who has his or her name, height, weight, gender ...

A module also has its own method. The so-called method is what this module can do. Give me a chestnut-_-!!

1 Import  Time 2 a=time.time ()3print(a)

Analysis:

1) since it is a module, only in the import (some modules need to install themselves, but also involved in the package dependencies, will be discussed later). Format is: Import module name

The above is the import of time (date and timeframe module).

2) Then create a new variable A, and assign a value. What is the value of the assignment? Time.time, the first time is the module name, the middle is separated by a dot, and the next time is the method name in the module.

3) Print a

Let's look at the print results together.

1 Import  Time 2 >>> a=time.time ()3print(a)4 1522146472.0563416

Here Time.time () returns a value in units of "seconds". Here, starting from zero January 1, 1970, the total number of seconds to the current time.

Second, if you want to know what the properties of a module, which methods, you can import imports first, and then use the DIR () this command.

1>>>Import Time2>>>dir (time)3['_struct_tm_items','__doc__','__loader__','__name__','__package__','__spec__','Altzone','Asctime','Clock','CTime','Daylight','Get_clock_info','gmtime','localtime','Mktime','monotonic','Perf_counter','Process_time','Sleep','strftime','Strptime','Struct_time',' Time','TimeZone','Tzname']

In the third row, the ' __doc__ ' format is the property of this module, and the ' clock ' format is the method of this module.

Advanced first Lesson Python module introduction

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.