Net-informations.com
SiteMap  | About    

How to use Split in Python

The split() method in Python returns a list of the words in the string/line , separated by the delimiter string.

Splitting String by space

The split() method in Python without an argument splits on whitespace.

example

output

Splitting on first occurrence

In the following example, it will Split by first 2 whitespace only.

example

output

Splitting lines from a text file in Python

The following Python program reading a text file and splitting it into single words in python

example

Splitting String by newline(\n)

output

Splitting String by tab(\t)

output

Splitting String by comma(,)

output

Split string with multiple delimiters

In this case Python uses Regular Expression.

example

output

Split a string into a list

The following Python program split a string to a List.

example

output









net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.