Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #22047 > unrolled thread
| Started by | "Prasad, Ramit" <ramit.prasad@jpmorgan.com> |
|---|---|
| First post | 2012-03-22 19:54 +0000 |
| Last post | 2012-03-22 19:54 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
RE: Odd strip behavior "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-03-22 19:54 +0000
| From | "Prasad, Ramit" <ramit.prasad@jpmorgan.com> |
|---|---|
| Date | 2012-03-22 19:54 +0000 |
| Subject | RE: Odd strip behavior |
| Message-ID | <mailman.906.1332446094.3037.python-list@python.org> |
> str1='this is a test'
> str2='t'
>
> print "".join([ c for c in str1 if c not in str2 ])
> print(str1.strip(str2))
>
> if __name__ == '__main__':
> main()
>
> ./remove_str.py
> his is a es
> his is a tes
>
> Why wasnt the t removed ?
This is not odd behavior, you just do not understand what
strip does. :)
The behavior is listed on the API. I highly recommend you
take time to become familiar with it.
http://docs.python.org/library/stdtypes.html#string-methods
str.strip([chars])
Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped:
>>>
>>> ' spacious '.strip()
'spacious'
>>> 'www.example.com'.strip('cmowz.')
'example'
Changed in version 2.2.2: Support for the chars argument.
Ramit
Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423
--
> -----Original Message-----
> From: python-list-bounces+ramit.prasad=jpmorgan.com@python.org
> [mailto:python-list-bounces+ramit.prasad=jpmorgan.com@python.org] On Behalf
> Of Rodrick Brown
> Sent: Thursday, March 22, 2012 2:49 PM
> To: python-list@python.org
> Subject: Odd strip behavior
>
> #!/usr/bin/python
>
> def main():
>
> Sent from my iPhone
> --
> http://mail.python.org/mailman/listinfo/python-list
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
Back to top | Article view | comp.lang.python
csiph-web