Join WhatsApp ChannelJoin Now

Python Split String Method Example

Hi Dev,

Today, i we will show you python split() string method example. This article will give you simple example of python split() string method example. you will split string character in python.

syntax : str.split(separator, maxsplit)

Parameters :
separator : This is a delimiter. The string splits at this specified separator. If is not provided then any white space is a separator.

maxsplit : It is a number, which tells us to split the string into maximum of provided number of times. If it is not provided then the default is -1 that means there is no limit.

Returns : Returns a list of strings after breaking the given string by the specified separator.

So let’s follow few step to create example of python split() string method example.

Example 1:

text = 'a b c'

# Splits at space

word = 'd, e, f'

# Splits at ','


['a', 'b', 'c']

['d', 'e', 'f']

Example 2:

word = 'This, is, python, example'

# maxsplit: 0
print(word.split(', ', 0))
# maxsplit: 4
print(word.split(', ', 4))
# maxsplit: 1
print(word.split(', ', 2))


['This, is, python, example']

['This', 'is', 'python', 'example']

['This', 'is', 'python, example']

I hope it will assist you…

Recommended Posts