Python – Split string example

Posted on Updated on

String is widely used in Python programming language. There are many scenarios where programmers have to split the string based on different delimiters. In this blog, we demonstrate splitting of string using different delimiters.

1) Split string using default delimiter

By default, split() method takes whitespace as delimiter.

Output

2) Split string using delimiter other than default

You can split string other than default delimiter. Below example demonstrate splitting of string using delimiter¬†‘.'(dot).

output

3) Control maximum number of tokens using split()

Using split(([sep [,maxsplit]])), you can control maximum number of tokens. Below example demonstrate controlling maximum number of tokens while spitting the string.

output

Stay tuned for more updates and tutorials !!!

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.