Example 1:

      
          
# Splitting the string into a list of words
sentence = "This is an example sentence."
words = sentence.split()
print(words)
# Printing the type of the data structure produced by split()
print("The type of the data structure produced by split():", type(words))
# output:['This', 'is', 'an', 'example', 'sentence.']
The type of the data structure produced by split():           

Example 2:

      
          
#spliting a date string
date_str = "2024-03-24"
date_components = date_str.split('-')
print(date_components)
#output:['2024', '03', '24']          

Example 3:

      
          
#spliting a Time string
time_str = "12:45:30"
time_components = time_str.split(':')
print(time_components)
#output:['12', '45', '30']          

Example 4:

      
          
# spliting a CSV[Comma separated file]
csv_str = "John,Bear,30,Pycent.com, New York"
csv_components = csv_str.split(',')
print(csv_components)
#output:['John', 'Bear', '30', 'Pycent.com', ' New York']          

Example 5:

      
          
#spliting a string with specific delimiter
text = "apple#banana#cherry#date#Pycent#.com"
items = text.split('#')
print(items)
#output:['apple', 'banana', 'cherry', 'date', 'Pycent', '.com']          

Example 6:

      
          
#spliting a string on the first delimiter
text = "one:two:three:four:John:Bear"
limited_split = text.split(':', 1)
print(limited_split)
#output:['one', 'two:three:four:John:Bear']          

Example 7:

      
          
#spliting an email into username and domain name
email = "johnbear@pycent.com"
parts = email.split('@')
print(parts)
#output:['johnbear', 'pycent.com']           

Example 8:

      
          
# spliting an email to get domain name, and further split to get extension
email = "johnbear@pycent.com"
username, domain = email.split('@')
domain_parts = domain.split('.')
print(username, domain_parts)
#output:johnbear ['pycent', 'com']          

Example 9:

      
          
# spliting the domain name from an email without the subdomain
email = "info@sub.example.com"
_, domain_and_tld = email.split('@')
domain, _, tld = domain_and_tld.rsplit('.', 2)
print(f"Domain: {domain}, TLD: {tld}")
#output:Domain: sub, TLD: com          

Example 10:

      
          
#spliting path into folders
path = "/home/user/docs/letter.txt"
path_parts = path.split('/')
print(path_parts)
#output:['', 'home', 'user', 'docs', 'letter.txt']