Chapter 15. Import Python development [module]

Import statements

The import statement

grammar:

import 模块名1 [as 模块别名]

effect:

The entire module is a module into the current

Example:

import math
import sys,os

usage:

Module name attribute name

math.factorial(5)

print(math.pi)

dir (obj) function returns all properties of the module list of strings
help (obj) function, you can view documents related to the string module

from import * statement

grammar:

from 模块名 import *

effect:

All the attributes of a module into the current module

Example:

from math import *
print(factorial(5))
print(sin(pi/2))

dir ([Object]) Returns a list of strings
action dir function:
If no arguments, the list of all variables in the current scope is returned
if a given object as a parameter, a list of all the variables of the object is returned
to a module, returns this module all the variables (attributes)
for a class object, returns the class object all the variables, and recursively base class for
all of the variables of the object
to the other object, and returns all the variables, class variables and class variables yl

Math module

Module name: math

Function name description
math.ceil(x) X is rounded up to, for example x = 1.2, 2 return
math.floor(x) X rounded down to, for example x = 1.2, returns 1
math.sqrt(x) Returns the square root of x
math.factorial(x) Find the factorial of x
math.log(x[, base]) Returns to base logarithm to the base x, if not given base, places the natural logarithm base e
math.log10(x) Seeking to base 10 logarithm of x
math.pow(x, y) Back x ** y (x power of y)
math.fabs(x) Returns the absolute value of the floating point number x
Angle and curvature degrees swap
math.degree(x) Radians to degrees x
math.radians(x) The angle x is converted to radians
Trigonometric functions
math.sin(x) Returns the sine of x (x in radians)
math.cos(x) Returns the cosine of x (x in radians)
math.tan(x) Returns the tangent of x (x in radians)
math.asin(x) Returns the arc sine of x (return value in radians)
math.acos(x) Returns the arc cosine of x (return value in radians)
math.atan(x) Returns the arctangent of x (return value in radians)

Time Module time

  • This module provides functions related to time, and always available

About Time

  • It is the beginning of the Christian era AD 0000 years from January 1 of 0
  • The computer is the first year from 1 January 1970 starting at 0:00, when time is 0, +1 after every passing second time
  • UTC time (Coordinated Universal Time) is the time counted from Greenwich.
    UTC time will not generate an error due to time zone issues
  • Sunshine saving time DST (Daylight Saving Time), also known as daylight saving time is a time elapsed after the time correction sunshine

Time tuple

  • A tuple is a time integral elements 9, which from front to back nine elements as follows:
    • Four-digit year (eg: 1993)
    • Month (1-12)
    • Day (1-31)
    • When (0-23)
    • Points (0-59)
    • Sec (0-59)
    • Day of the week (0-6, Monday is 0)
    • New Year's start date (1-366)
    • Correction time (-1, 0 or 1) for daylight saving time.
  • Note:
    • If the value is less than 100 years, it will be automatically converted to a value obtained by adding 1900

Module name: time

Time Module usage:

import time
# 或
from time import xxx
# 或
from time import *
data description
time.altzone Daylight saving time difference to the UTC time (seconds)
time.daylight Daylight saving time correction
time.timezone This difference in local time and UTC time (seconds)
time.tzname Time zone name tuple, the first name is not revised daylight saving time zone name, first name as amended by the daylight saving time zone name

Note: CST is China Standard Time (China Standard Time UTC + 8: 00)

Function name description
time.time() Returns the number of seconds from float year computer to the current time (UTC time)
time.sleep(secs) The program to a given number of seconds the float sleep for some time
time.gmtime([secs]) Convert a given number of seconds time tuple expressed in UTC (default tuple returns the current time)
time.asctime([tuple]) The conversion time is a date time string tuple
time.mktime(tuple) Converting the local date and time tuple Epoch seconds Time (UTC date)
time.localtime([secs]) Seconds to convert UTC time date tuple (subject to local time)

System Module sys

  • Related information when the system is running

Sys data module

data description
sys.path Module search path path [0] is the name of the current path of the script, otherwise ''
sys.modules Loaded modules dictionary
sys.version Version information string
sys.version_info Named tuple version information
sys.platform Operating system platform name information
sys.argv Command line arguments argv [0] represents the path name of the current script
sys.copyright Access to information related to copyright Python
sys.builtin_module_names Name (string tuple) built-in module is obtained Python

Function sys module

Function name description
sys.exit([arg]) Exit the program, when the normal exit sys.exit (0)
sys.getrecursionlimit() Obtained recursively nested level limit (stack depth)
sys.setrecursionlimit(n) Obtained recursively nested hierarchy restrictions and modifications (stack depth)

Guess you like

Origin www.cnblogs.com/pyliuwei/p/11846989.html