Python self-study day-Two day (1)-python environment variables, module first Knowledge and character type, python-python
(1) Module
Standard module, third-party module
Initial module: sys \ OS
Standard inventory path C: \ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python35 \ Lib
Third-party reference installation inventory path: C: \ Users \ Administrator \ AppData \ Local \ Programs \ Python \ Python35 \ Lib \ site-packages
Module reference example:
Import sysimport osprint (sys. path) # print the environment variable path print (sys. argv) # print the relative path OS of the current script. system ("dir") # print the output, but do not save the result. Only the execution success or failure value is returned. _ memory = OS. popen ("dir") print (_ memory) # print the output memory address print (_ memory. read () # print the directory list OS. mkdir ("new_dir") # create a directory OS. rmdir ("new_dir") # delete a directory
Pyc c (compile) compilation, (pre-compiled bytecode file) after the custom module is referenced, A pyc file will be generated (compilation result) the next reference will first read the file ending with pyc and load it directly to avoid repeated compilation.
Python character type
Type () view Character Types
1. Number
Int integer
Long integer (no long integer type after Python3)
Float
Complex Number of complex
2. Boolean Value
True and false
1 and 0
3. String
String
4. bytes byte type
Mutual conversion between strings and binary bytes
String. encode (encoding = "UTF-8") string to binary bytes
Bytes. decode (encoding = "UTF-8") binary conversion to a string
# String-byte conversion str = "I love you, you can not love me" print ('--------', str. encode (encoding = "UTF-8 ")) byt = B '\ xe6 \ x88 \ x91 \ xe7 \ x88 \ xb1 \ xe4 \ xbd \ xa0 \ xef \ xbc \ x8c \ xe4 \ xbd \ xa0 \ xe5 \ x8f \ xaf \ xe4 \ xbb \ xa5 \ xe4 \ xb8 \ x8d \ xe7 \ x88 \ xb1 \ xe6 \ x88 \ x91 'print ('------', byt. decode (encoding = "UTF-8 "))
Ternary Computation
Result = a1 if condition else a2