Module
Module is a very simple Python file, a single python file is a module, two files is two modules.
What is the function of the Python module?
1, the module has many function methods, using these methods can be more simple to do a lot of work.
2, the module can permanently save the code in the file. Manipulating the input code in the Python interactive interpreter is not saved when exiting Python, and the code in the module file is permanent.
3, from the practical aspect, the module can be used across the system platform, only need to copy code. For example, there is a global pair of images that will be used by many files, which is the best way to make it easier to write to a module and then be called.
Built-in Modules
Time Module
The time module contains the following built-in functions, both temporal and conversion time formats:
1.time.localtime ([secs]): Converts a timestamp to the struct_time of the current time zone. The secs parameter is not provided, whichever is the current time.
2.time.gmtime ([secs]): Similar to the LocalTime () method, the Gmtime () method is the struct_time of converting a timestamp to the UTC time zone (0 o'clock Zone).
3.time.time (): Returns the timestamp of the current time.
4.time.mktime (t): Converts a struct_time to a timestamp.
5.time.sleep (secs): Thread delays the specified time run. Unit is seconds.
6.time.clock (): This needs to be noted on different systems with different meanings. On a UNIX system, it returns "process time", which is a floating-point number (timestamp) in seconds. In Windows, the first call returns the actual time that the process is running. The second subsequent call is the elapsed time since the first call to the present. (actually based on QueryPerformanceCounter () on WIN32, which is more accurate than milliseconds)
7.time.asctime ([t]): A tuple or struct_time representing time is expressed in this form: ' Sun June 20 23:21:05 1993 '. If there are no parameters, Time.localtime () will be passed in as a parameter.
8.time.ctime ([secs]): Converts a timestamp (floating point number in seconds) to the form of Time.asctime (). If the parameter is not given or is none, the default Time.time () is the parameter. Its function is equivalent to Time.asctime (time.localtime (secs)).
9.time.strftime (format[, T]): Converts a tuple or struct_time that represents time (such as returned by Time.localtime () and Time.gmtime ()) to a formatted time string. If T is not specified, the Time.localtime () is passed in. If any of the elements in the tuple are out of bounds, the ValueError error will be thrown.
10.time.strptime (string[, format]): Converts a formatted time string to Struct_time. In fact it is inverse operation with strftime ().
2.random
Random
1. Introduction
The random is used to generate randomly generated numbers, and we can use it to randomly generate a number or select a string
in the interval [0, 1import random>>> random.random () 0.999410896951364
2.
Random.randint (A, B)
Used to generate a specified range of integers, a is the lower bound, B is the upper limit, the resulting random integer a<=n<=b; if a=b, then n=a; if a>b, error
>>> random.randint (10,10)10>>> random.randint (10,20)12>>> Random.randint (20,10)
3.
Random.randrange ([start], stop, [, step])
Gets a random number in the collection that increments by the specified cardinality from the specified range, and the base default value is 1
>>> Random.randrange (10,100,5)80
4.
Random.choice (Sequence)
Gets a random element from the sequence, the parameter sequence represents an ordered type, not a specific type, refers to List,tuple, a string, etc.
>>> Random.choice ([1,3,8,9])8>>> random.choice ([1,3,8,9])9>>> Random.choice ([1,3,8,9])9>>>
5.
Random.shuffle (x[, Random])
Used to disrupt elements in a list
>>> a = [1,2,3,4,5]>>> random.shuffle (a)>>> a[4, 5, 2, 1, 3]< /c3>>>> Random.shuffle (a)>>> a[3, 2, 5, 1, 4
Python Dafa Good--module (built-in module not finished)