Recognize modules: A Code < statement block < code block (function, Class) < module.
Collections (Clecksons)
1. Counter # is used to view the number of occurrences of a character.
"upup qwe"
Queue: FI FO. FIFO stack: FI LO. Advanced Post-out
2.deque (bidirectional queue) from collections import Deques = Deque () s.append ( " Wahaha S.append ( " Nutrition Express " Span data-mce-= "" > S.appendleft ( " Cool crooked ") # Left Add print (s) Print (S.pop ()) print (S.popleft ()) # Left delete
3.namedtuple (named tuple)# from collections import namedtuple# NT = namedtuple ("point", ["X", "Y"])# p = NT (1, 2)# print (P)# print (p.x)# print (p.y)
Time Module
The time in Python is divided into three forms of expression:
1. Timestamp (timestamp)
Import timeprint (Time.time ())
2. Format time (strftime)
Import Time
s = Time.strftime ("%y-%m-%d%h:%m:%s")print (s)
3. Structured time (Struct_time)
Print(Time.localtime ()) Results: Time.struct_time (tm_year=2017, tm_mon=05, Tm_mday=8, tm_hour=10, tm_min=24, tm_sec=42 , Tm_wday=0, tm_yday=126, tm_isdst=0)
All conversions are transformed through structured time.
Random number Module
ImportRandomprint (Random.random ()) # 0-1 decimal print ( Random.uniform (3,10)) 3-10 decimal print (Random.randint (1,10)) 1- 10 integer print (Random.randrange (1,10,2)) 1-10 odd print (Random.choice ([1, ' Jay ", [ Span data-mce-= "" " Galen " hu Spicy Soup print (Random.sample ([1, 23 ", [4, 5], 2)" Any 2 combinations of list elements Random.shuffle (LST) # Random Shuffle order
OS and OS-related modules
Import osos.makedirs ('a/b/c/d') creates multi-layered os.removedirs ('dirname1') Delete Os.mkdir ( 'dirname') create a single layer Os.rmdir ('dirname') todelete the single layer Os.rename ("oldname ","newname") Rename os.getcwd () Get current? Make directory
SYS and Python interpreter-related modules
sys.argv command line argument list, the first element is the program itself path Sys.exit (n) exits the program, exit normally exits (0), error exits Sys.exit (1) sys.version Gets the version information of the Python interpreter Sys.path returns the search path of the module, which is initialized with? Pythonpath the value of the environment variable Sys.platform returns the operating system platform name
Module (collections, Time, random, OS, SYS)