Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to Split Strings in python

s = 'KDnuggets is a fantastic resource'

print(s.split())

# Output

# ['KDnuggets', 'is', 'a', 'fantastic', 'resource']


# By default, split() splits on whitespace,
# but other character(s) sequences can be passed in as well.

s = 'these,words,are,separated,by,comma'
print('',' separated split -> {}'.format(s.split(',')))

s = 'abacbdebfgbhhgbabddba'
print(''b' separated split -> {}'.format(s.split('b')))


# ',' separated split -> ['these', 'words', 'are', 'separated', 'by', 'comma']
# 'b' separated split -> ['a', 'ac', 'de', 'fg', 'hhg', 'a', 'dd', 'a']
Source by www.kdnuggets.com #
 
PREVIOUS NEXT
Tagged: #How #Split #Strings #python
ADD COMMENT
Topic
Name
3+8 =