[Tutor] String method "strip()" not working

Alan Gauld alan.gauld at btinternet.com
Sat Mar 7 15:54:17 CET 2015


On 07/03/15 13:15, Akash Shekhar wrote:
> I am trying to learn how to use strip() method. It is supposed to cut out
> all the whitespace as I read in the tutorial.

Read it again more closely.

-------------------
Help on built-in function strip:

strip(...)
     S.strip([chars]) -> string or unicode

     Return a copy of the string S with leading and trailing
     whitespace removed.
     If chars is given and not None, remove characters in chars instead.
     If chars is unicode, S will be converted to unicode before stripping
----------------------

So it only strips leading and training whitespace, not the whitespace 
inside the string. (Use str.translate() for that)
HTH

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list