how to split a string into multiple strings in python code example
Example 1: how to split a string in python with multiple delimiters
>>> a='Beautiful, is; better*than\nugly'
>>> import re
>>> re.split('; |, |\*|\n',a)
['Beautiful', 'is', 'better', 'than', 'ugly']
Example 2: split string python
file='/home/folder/subfolder/my_file.txt'
file_name=file.split('/')[-1].split('.')[0]
Example 3: python split string on char
>>> "MATCHES__STRING".split("__")
['MATCHES', 'STRING']
Example 4: how to split a string into two strings python
test_str = "GeeksforGeeks"
print("The original string is : " + test_str)
res_first, res_second = test_str[:len(test_str)//2],
test_str[len(test_str)//2:]
print("The first part of string : " + res_first)
print("The second part of string : " + res_second)