Python Learning Notes
1 Import:
(1) Import module
(2) from module import argv
(3) from module import *
2 Item:
Item: Each pair of keys and value in the dictionary is composed of a tuple and returned (returned by the key and Vaule of one of the elements in the dictionary)
3 Split:
There are two split functions in Split:python:
Split (): Splits the string. Slices a string by the specified delimiter and returns the segmented list of strings
Os.path.split (): Splits the file name and path by path.
(1) Split () function:
Str. Split (delimiter, number of splits) [select part: Left or right]
Example: Splitting a string
str = "www.baidu.com.cn!!!!!"
Print (Str.split ('. ‘ ))
[' www ', ' Baidu ', ' com ', ' CN!!!! ']
expressed in. Segmentation of STR for a delimiter
Print (str. split ('. '), 1)
[' www ', ' baidu.com.cn!!!! ']
Split only 1 times, the rest of the output is not split.
Print (str. split ('. '), 2) [0]
[' Baidu ']
Split two times, take the right part: 0 means the left split string 1 means the right
STR1, str2, STR3 = str. Split ('. ', 2)
Print (str1) ===== www
Print (STR2) ===== Baidu
Print (STR3) ====== com.cn!!!!
(2) Separating the file name and path:
Import OS
Print (OS. path. Split ('/var/panoview/modules/setup/time.js '))
('/var/panoview/modules/setup ', ' time.js ')
For example: str = "Hello boy < [www.daidu.com]> bye Bye"
Print (str. split ("[") [1]. Split ("]") [0])
Www.daidu.com
4 Strip:
Statement: S is a string, dest is a sequence of characters that need to be deleted
S.strip (dest): Deletes the character in the character sequence at the beginning and end of the entire string
S.lstrip (dest): Delete Only the beginning
S.rstrip (dest): Delete Only the end
Attention:
When Dest is empty, the default whitespace deletion includes: ' \ n ', ' ', ' \ t '
Example:
str = "Hello word"
Str. STRIP ()
Hello Word
str = "# #!!! # #hello word \ n 123 "
Str. STRIP ("#!\n 123")
Hello Word
Str. Lstrip ("#!")
Hello Word \ n 123
Str. strip ("\ n 123")
##!!! # #hello Word
5 encode:
Encode encoding Method:
Str. Encode (enconding = "UTF-8", errors = "strict")
enconding----need to use the encoding method
Errors--------to set different error handling methods
6 Input:
This article from "12690807" blog, declined reprint!
Python Learning Notes