Python split string, filter function usage, pythonsplit
For an existing string, you need to extract the first segment separated by spaces. The operation is as follows:
>>> Product_model = 'ws-C2960G-24TC-L-Fixed Module 0 ′
>>> Product_model.split ('') [0]
'Ws-C2960G-24TC-L'
Split () without parameters, all spaces (space characters, tabs, line breaks) are used as separators. If these spaces exist, you can write them like this.
>>> Product_model = 'ws-C2960G-24TC-L-Fixed Module 0 ′
>>> Product_model.split () [0]
Filter is used to filter data.
>>> Product_model = 'ws-C2960G-24TC-L-Fixed Module 0 ′
>>> Filter (None, product_model.split ('-'))
['Ws ', 'c2960g', '24tc', 'l', 'fixed Module 0']
Article from: http://www.111cn.net/phper/python/64510.htm
Python split () is separated by spaces by default. Now there are # and space in the string. How can split only by #, not by space?
The use of split () is like this. You only need to add in the brackets What You Need To split. For example, if you want to split with #, then split ("#"). For example, a = "a # a", B = a. split ("#") >>> print B to output [a, a, a]
Use of split in python
The default delimiter of the string split function is space''
If no separator exists, the entire string is used as an element in the list.