One, two modules (SYS and OS)
1 #!/usr/bin/env python2 #_*_ coding:utf-8 _*_3 #Author:taoke4 ImportSYS5 Print(Sys.path)#Print Environment Variables6 Print(Sys.argv[0])#current file relative path, SYS.ARGV is a list, the first element is the relative path of the program itself, followed by the input parameters for the program to run7 8 ImportOS9 #cmd_res= Os.system ("dir") #执行命令不保存结果TenCmd_res = Os.popen ("dir"). Read ()#saves the result of the command execution and returns the Save Address One Print(" -", Cmd_res) AOs.mkdir ("New_dir")#Create a directory
SYS and OS two modules for ease of use
Import
Now looking for modules in the current directory, looking for modules in environment variables
Path for storing third-party modules C:\Python36-32\Lib\site-packages
Second, the conversion between string and bytes in Python
1 #!/usr/bin/env python2 #_*_ coding:utf-8 _*_3 #Author:taoke4str ="I love Beijing Tian ' an gate"5Str_endode = Str.encode ("Utf-8")6Str_endode_decode = Str_endode.decode ("Utf-8")7 Print(Str,type (str))8 Print(Str_endode,type (str_endode))9 Print(Str_endode_decode,type (Str_endode_decode))
<class'str'>b'\xe6\x88\x91\xe7\x88\xb1\xe5\x8c \x97\xe4\xba\xac\xe5\xa4\xa9\xe5\xae\x89\xe9\x97\xa8' <class' Bytes'><class'str'>
Three, List
1 #!/usr/bin/env python2 #_*_ coding:utf-8 _*_3 #Author:taoke4names = ["xiaoming","Xiaohong","Xiaohei","Xiaoxiao"]5 6 Print(names)7 Print(names[0],names[2])8 Print(Names[1:3])#Gu Tou regardless of tail, slice9 TenNames.append ("xiaobingbing") One Print(names) ANames.insert (1,"Renma") - Print(names)
Shallow copy and deep copy in list
#!/usr/bin/env python#_*_ coding:utf-8 _*_#Author:taokeImportCopynames= ["xiaoming","Xiaohong",["Jack","Toms"],"Xiaohei","Xiaoxiao"]names2= Names.copy ()#Shallow CopyNames3 = copy.copy (names)#Shallow CopyNames4 = copy.deepcopy (names)#Deep CopyNames[2][0] ="JACK"Print(names)Print(Names2)Print(NAMES3)Print(NAMES4)
Operation Result:
['xiaoming','Xiaohong', ['JACK','Toms'],'Xiaohei','Xiaoxiao']['xiaoming','Xiaohong', ['JACK','Toms'],'Xiaohei','Xiaoxiao']['xiaoming','Xiaohong', ['JACK','Toms'],'Xiaohei','Xiaoxiao']['xiaoming','Xiaohong', ['Jack','Toms'],'Xiaohei','Xiaoxiao']
Iv. Tuple (tuple)
Can not change the list, can only check.
V. String (Method of strings)
- Str.rjust: Right-justified
- Str.ljust: Left Justified
- Str.center: Middle Alignment
- Str.zfill: The default way
- Str.find: String lookup, no return-1
- Str.index: Find string position, no error returned
- Str.rfind: Find from right
- Str.rindex: Ibid.
- Str.count: Count the number of occurrences of a string
- Str.replace: String substitution
- Str.strip: Remove whitespace at the beginning of the string
- Str.lstrip: Remove left space
- Str.rstrip: Remove Right space
- Str.expandtabs: Replace table in string with equal length space
- Str.lower:
- Str.upper:
- Str.swapcase: Reverses string character capitalization
- Str.capitalize: string First character uppercase
- Str.title: Capitalize first letter in string
- Str.split: string split into List
- Str.splitlines: Splitting a string into a list by rows
- '-'. Join (strlist): Concatenate list strlist into strings with '-'
- Str.startswith: Tests whether a string starts with a specified character
- Str.endswith: Tests whether a string is terminated with the specified character
- Str.isalum: Determines whether a string is full of characters or numbers and has at least one character
- Str.isalpha: Judging whether the string is all letters
- Str.isdigit: Judging whether the string is all numbers
- Str.isspace: Determine if a string contains spaces
- Str.islower: Determine if the string is all lowercase
- Str.isupper: Determine if the string is all uppercase
- Str.istitle: Determine if the first letter is uppercase
- Import string
- String.atoi ("123", BASE=10/8/16): Converts a string to a number of type int
- String.atol: Converting strings to long shaped numbers
- String.atof: Converting a string to a floating-point type
Python Learning record 2