相比较C++而言,Python 对于String的操作更为的容易,比如Split的操作

    1. txt = "welcome to the jungle"
    2. x = txt.split()
    3. print(x)
    4. // ['welcome', 'to', 'the', 'jungle']

    语法规则
    string.split(separator, maxsplit)
    separator - Optional. Specifies the separator to use when splitting the string. By default any whitespace is a separator
    maxsplit - Optional. Specifies how many splits to do. Default value is -1, which is “all occurrences”

    1. txt = "hello, my name is Peter, I am 26 years old"
    2. x = txt.split(", ")
    3. print(x)
    4. //['hello', 'my name is Peter', 'I am 26 years old']
    1. txt = "apple#banana#cherry#orange"
    2. x = txt.split("#")
    3. print(x)
    4. //['apple', 'banana', 'cherry', 'orange']
    1. txt = "apple#banana#cherry#orange"
    2. # setting the maxsplit parameter to 1, will return a list with 2 elements!
    3. x = txt.split("#", 1)
    4. print(x)
    5. //['apple', 'banana#cherry#orange']