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
- Java String.split () special character processing
- Type error: sequence item 0: expected STR instance, int found
- Java compareto() method
- Python: Understanding__ str__
- Pre initialization of list content and length in Python
- Translate() and maketrans() methods of string in Python
- Global variable error: unboundlocalerror: local variable ‘l’ referenced before assignment
- The function and usage of argc and argv in C language
- Continue Long Statements on Multiple Lines Matlab
- Tensorflow in function tf.Print Method of outputting intermediate value
- The reason and solution of the error of join function: sequence item 0: expected STR instance, int found
- Mybatis custom list collection parser
- Common attributes and methods of list and map in Dar
- Conversion between list and string array
- Explanation of the function strip(), lstrip(), rstrip() in Python
- Import sys module
- In Python, print() prints to remove line breaks
- From in Python__ future__ The role of import *
- The conversion between [Python] bytes and hex strings.