Python programming---string indexing & slicing

                                       String indexing and slicing

1. String index

analysis:

  1. String has its own corresponding index information
  2. The index value starts from 0 until the last character;
  3. The index value can start from -1 (the last character) until the first character;
  4. If the index is out of range, the system will report an Error IndexError .

2. String slicing

Slicing : You can arbitrarily select consecutive segments in the string

3. Get the index value of the specified character in the string

Usage : stringObject. index ("specifiedCharacter")

 

Guess you like

Origin blog.csdn.net/yanlaifan/article/details/114802188