Tuesday, August 28, 2012

how to split the given statement using split() function in python


s = input("enter any sentence")
for w in s.split():
    print(w)

this script will split the entered sentence based on the space 

if we entered the sentence as  , python is using by rby , then result is 

python
is
using
by
rby

if we use the split like below 

s = input("enter any sentence")
for w in s.split(':'):
    print(w)


then 

it will work as follows

ramesh:rby:python


ramesh
rby
python

No comments:

Post a Comment