String split and join in Python

Here we explain String split and join in Python.

Python provides us with various inbuilt functions, two of which are split and join.

String Split in Python

Split is a function in which we can split a string.

Syntax: split()

Example: of split() function

String = "Example on Split function"
String = String.split(" ") 
print String
['Example', 'on', 'Split', 'function']

Here we have taken a variable name as String which stores a string Example on Split function then calling the function split(). It splits the content of the String variable and stores in the String variable.

String Join in Python

Join is a function in which can be used to join various words or sentences separated by any keyword.

Syntax: join()

Example of join() function

String="Apple Orange Mango"
String = ",".join(String)
print String

Here also we have taken a variable name String which stores Apple Orange Mango and we have called join() function which separates each word by a comma and then prints it.

Also read:

Leave a Reply

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