How to split a string into words in Python

3 Answers

0 votes
s = 'python programming language'

words = s.split(" ")

for w in words:
    print(w)

'''
run:

python
programming
language

'''

 



answered Feb 5, 2017 by avibootz
0 votes
import re

s = '-python,,, programming... language!'

print(re.findall(r"[\w']+", s))

'''
run:

['python', 'programming', 'language']

'''

 



answered Feb 5, 2017 by avibootz
0 votes
import re

s = '-python,,, programming... language!'

words = re.findall(r"[\w']+", s)

for w in words:
    print(w)

'''
run:

python
programming
language

'''

 



answered Feb 5, 2017 by avibootz

Related questions

1 answer 237 views
1 answer 119 views
1 answer 207 views
2 answers 241 views
2 answers 272 views
3 answers 306 views
...