Python Tutorial

Tuesday, August 17, 2010

python String Strip

'''
    This code is use for strip a string/line
'''
data = " Life is very easy with Python   "
print data
data=data.strip()
print data
data = "  Life is very easy with Python   "
'''
    Remove only trailing space
'''
data=data.rstrip()
print data
'''
    Remove only leading space
'''
data=data.lstrip()
print data
data=",,,,Life is very easy with Python,,,,,"
print data
'''
    remove leading and trailing commas
'''
data=data.strip(",")
print data



Output:
Life is very easy with Python   
Life is very easy with Python
  Life is very easy with Python
Life is very easy with Python
,,,,Life is very easy with Python,,,,,
Life is very easy with Python

0 comments:

Post a Comment