format string/compound field name
>>> import humansize>>> si_suffixes = humansize. suffixes[1000]>>> si_suffixes[' KB ', ' MB ', ' GB ', ' TB ', ' PB ', ' EB ', ' ZB ', ' YB ']>>> ' 1000{0[0 '} = 1{0[1]} ' . Format (si_suffixes) ' 1000KB = 1MB '
>>> Import humansize>>> Import sys>>> ' 1MB = 1000{0.modules[humansize]. Suffixes[1000][0]} '. Format (SYS) ' 1MB = 1000KB '
Sys.modules is a dictionary that holds imported modules in the current Python instance. The module's name is the key, and the module itself is a value.
>>> a_list = Query.split ("&") >>> a_list[' User=pilgrim ', ' database=master ', ' password= Papayawhip '] >>> a_list_of_list = [V.split (' = ', 1) for V in a_list]>>> a_list_of_list[[' user ', ' Pilgrim '], [' Database ', ' master '], [' Password ', ' papayawhip ']] >>> a_dict = dict (a_list_of_list) >>> a_dict{' Password ': ' papayawhip ', ' database ': ' Master ', ' user ': ' Pilgrim '}
Split ()-separates the string into a list of strings, based on the specified delimiter.
Dict ()-Converts the list of included lists into a Dictionary object
Shard of a string
>>> a_string = "My alphabet starts where your alphabet ends." >>> a_string[3:11] ' alphabet ' >>> a_string[3:-3] ' alphabet starts where your alphabet en ' >>> a _STRING[:18] ' My alphabet starts ' >>> a_string[18:] ' where your alphabet ends. '
String VS. Bytes
Definition of bytes object: B ', eg:by = B ' abcd\x65 '
The bytes object cannot change its value, but the Bytes object can be converted to a Bytearry object through the built-in function Bytearry (), and the value of the Bytearry object can be changed
>>> a_string = "dive into Python" >>> by = A_string.encode (' utf-8 ') >>> byb ' dive into Python ' ;>> roundtrip = By.decode (' Big5 ') >>> roundtrip ' dive into Python '
String.encode ()--Converts a string to a bytes object using some encoding as an argument.
Bytes.decode ()--Converts the Bytes object to a string object using some encoding as a parameter.
Python Learning Note 3-string