Pages

Monday, January 10, 2011

SubString in Python

Consider I have a String as follows

var="Welcome to Python"


To split into substrings , we can use the method,
split("delimiter")




If I wish to split the above string based on space,then I
should give as,

out=var.split(" ")

Now split () Method will return a list.

You can either access it with for loop as follows,

for i in out:
     print i


(or)

Use indexed access .

print out[0]
print out[1]
print out[2]

No comments:

Post a Comment