SoFunction
Updated on 2025-03-02

Detailed explanation of Python string split and rsplit method principles

1. Description

Split() method slices the string by specifying the separator. If the parameter num has a specified value, it separates num+1 substring. The default separator is all empty characters, including spaces, line breaks (\n), tab characters (\t), etc.

The rstrip() method passes

2. Syntax

([sep=None][,count=(sep)])

([sep=None][,count=(sep)])

3. Parameters

  • sep -- Optional parameter, specified delimiter, default to all null characters, including spaces, line breaks (\n), tab characters (\t), etc.
  • count -- Optional parameter, number of splits, default is the total number of times the delimiter appears in the string

4. Return value

Returns the split string list, which can be received with a new string.

5. Example

str1 = "Hao123 hao456 hAo789"
new_str = ()
new_str2 = (' ', 1)
new_str3 = (' ', 1)

print(new_str)
print(new_str2)
print(new_str3)

#The output result is as follows:['Hao123', 'hao456', 'hAo789']
['Hao123', 'hao456 hAo789']
['Hao123 hao456', 'hAo789']

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.