A statement
0- an ordered sequence of multiple characters;
Second, characteristics
1, a string data type is immutable
2, the string is ordered
Third, the index
Subscript: 'abcde'
1, from left to right, 0, 1, 2, ...
2, right to left, the last character index value -1
The inverse of the index value of the second character-2 ....
Slice:
string [start: stop: step]
* Start: can take to
* stop: not take
care regardless tail
* start: default from the beginning
* stop: The default is taken to the end
N is 1. step
1, cut from left to right, the positive sequence
2, start <stop
2, step is negative
1, still follow the rules of care regardless of the end of the
2, from right to left cut
3, start> stop
s = 'abcde'
'abc' --> s[0:3:]
'cba' --> s[2::-1]
length
len (string) # python built-in functions
解包
x, y, z = 'abc' # x = 'a' z = 'c'
Fourth, the common method string
1. Find
find () to find, from the left to return the specified character index in the string value
rfind () to find, starting from the right to return the specified character index value in a string of
more than two, if can not find the time, or -1
index () to find, from the left to return the specified character index value in the string
rindex () to find, starting from the right to return the specified character index value in a string of
more than two, if can not find the time, error
count () calculates the number of times specified character string appearing in
2. Split
The splitlines () splits on line breaks, after the split of strings to be placed in a list of
split (sep, maxsplit)
Function: a character string in accordance with the cut, the remaining portion not cut
sep : who accordance cutting, cutting rules
1 s = 'i love python' 2 s.split(' ') ---> ['i', 'love', 'pyhton']
maxsplit: the number of cutting; cutting all the default;