describe
Python split() slits a string by specifying a delimiter, and only splits the num substring if the parameter num has a specified value
grammar
Split () method syntax:
Python split() slits a string by specifying a delimiter, and only splits the num substring if the parameter num has a specified value
grammar
Split () method syntax:
str.split(str="", num=string.count(str)).
parameter
STR – The delimiter, which defaults to all null characters, including Spaces, newlines (\n), tabs (\t), and so on. Num – number of splits.
The return value
Returns a list of partitioned strings.
The instance
The following example shows how to use the split() function:
#!/usr/bin/python
str = "Line1-abcdef \nLine2-abc \nLine4-abcd";
print str.split( );
print str.split(' ', 1 );
The output of the above example is as follows:
['Line1-abcdef', 'Line2-abc', 'Line4-abcd']
['Line1-abcdef', '\nLine2-abc \nLine4-abcd']
Read More:
- Split keyword in ABAP when the separator is at the beginning and end of the string
- How to Split numbers and strings in a strings
- How to use C + + function pointer array
- Java String.split () special character processing
- Split screen display method in IntelliJ idea
- nvalid default value for prop “params“: Props with type Object/Array must use a factory function to
- How to Use the Reverse() Function
- Array of PHP_ diff,array_ intersect,array_ merge, in_ Is there a limit on the number of arrays in array?
- How to solve oserror: [errno 98] address already in use and kill the python3 process
- Come and watch! Let’s see how people use Python to visualize the congestion situation of cities
- Python – get the information of calling function from called function
- python MemoryError: Unable to allocate 165. MiB for an array with shape
- “Could not import PIL.Image . The use of array_ to_ The solution of img requires PIL. “
- How to Fix TypeError: Cannot cast array data from dtype(‘float64‘) to dtype(‘<U32‘)….
- Explanation of the function strip(), lstrip(), rstrip() in Python
- [solved] error: valueerror: expected 2D array, got scalar array instead
- Two dimensional array and pointer to one dimensional array
- The use of C + + template function and lambda expression
- Use of rep function in R
- Use Python to insert the specified content in the specified line of the specified file