Using Modules
(coll.) fail (a student)importWhen a module,Do three things automatically: 1. Run through all the code in the module(Ensure that this module does not havebug) 2. Generate a namespace,This name is the same as the module name 3. Let the running program connect to the namespace,Subsequently, you can use the variables in the module/function (math.) pythonSelf-contained variables in the file:__name__,in the event thatpyThe file is run as a program,__name__ = 'main',in the event that以模块的方式运行,__name__ = filename
time - time module
import time (2) # Program pause in seconds # Get timestamp print(()) # Formatted output time print(('%Y-%m-%d %H:%M:%S'))
sys - system module
import sys # Get environment variables print() print() print()
random - any number module
import random # Generate a (0,1) random number print('%.3f' % ()) print((1,100)) # Randomly take a value from the sequence li = [1,2,3,4] c = (li) print(c) # Disrupt the ordering of a list (li) print(li)
os - Operating System Module
import os # Get current file location pwd print(()) # Create a new folder ('aaa') # Get the operating system's file separator
summarize
That's all for this post, I hope it was helpful and I hope you'll check back for more from me!