Python value string str

  1. string spans more than one line, with triple quotes (single or double quotation marks):

    '''

      first row

      second line

      The third row

    '''

  2. Index: String moment iteration. The first character is index 0, after each index plus one.

      Python also supports negative index (negative index): from right to left can be used to find the index iterables of elements (must be a negative number). Index-1 can be found in the last element iteration object.

    例: author = " Kafka"

      print(author[1])

      print(author[-2])

      >>>> 'a'

      >>>> 'k'

   3. The strings are immutable: you want to modify the string, you must create a new string

   4. string concatenation: using the addition operator, the two or more strings together to form a new string

   5. Multiplication string:

      例:"abc" * 3

        >>>> abcabcabc

   6. Change Case:

      1) upper () method, each character in the string to uppercase: Example: "Hello" .upper ()

      2) lower () method, each character string to lowercase: Example: "Hello" .lower ()

      3) capitalize () method: string to uppercase first letter: Example:. "! Hello world" capitalize ()

   7. Format: can be used to create a string format, the method of the string "{}" is replaced with the string passed

      例:“Hello {}”.format("world")   

        >>>> "Hello world!

   8. The split split () method: for string is divided into two or more strings.

      例:"I am a student. My name is liuming .".split(".")

        >>>> "I am a student" ,  "My name is liuming"

   9. connection: the Join () method: the character can be added between each character string.

      例: ” + “.join("abc")

        >>>> 'a + b + c'

   10. The space removal strip () method: removing a blank character string of the beginning and end.

      例:s = "         the              "

        print(s.strip())

        >>>>  'the'

   11. Replace: Replace () Method: The first argument is the string to be replaced, the second parameter is used to replace the string.

       例:equ = "All animals are equal."

         equ =equ.replace("a", "@")

         print(equ)

         >>>> All  @nim@ls equ@l.

   12. Find the index index () method: Get a character index of the first occurrence of the string. If not found, python will be reported abnormal

      例:"animals".index("m")

        >>>> 3

   13. keywords in, not in: Checks if a string is a string of zero returns True or False

      例: "cat" in "cat in the hat"

        >>>> True

   14. The string escape "\": refers to have special significance in Python is a plus character symbol "\."

   15. newline: \ n,

   17. sliced ​​(slicing): 

      Grammar sections: [iterable] [[start Index: end index]]   

      When the elements comprising slice start position, the end position of the index element is not included.

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/lxk0210/p/12006501.html
Recommended