Code: Select all
>>> t = "win2.s2p"
>>> t
'win2.s2p'
>>> t.strip(".s2p")
'win'
Code: Select all
>>> t = "win2.s2p"
>>> t
'win2.s2p'
>>> t.strip(".s2p")
'win'
The order does not matter.dont_think_twice wrote: ↑Sat Feb 12, 2022 6:27 amWhat am I missing?Code: Select all
>>> t = "win2.s2p" >>> t 'win2.s2p' >>> t.strip(".s2p") 'win'
Code: Select all
In [7]: t.strip('2sp.n')
Out[7]: 'wi'
Code: Select all
In [1]: a = 1234
In [2]: b = 1234
In [3]: a is b
Out[3]: False
In [4]: a = 115
In [5]: b = 115
In [6]: a is b
Out[6]: True
Python is allowed to automatically intern any immutable types, but not required to do so. Different implementations will intern different values.
CPython (the implementation you're using if you don't know which implementation you're using) auto-interns small integers and some special singletons like False, but not strings (or large integers, or small tuples, or anything else).
As others have pointed out "".strip(...) strips all occurances of the characters.dont_think_twice wrote: ↑Sat Feb 12, 2022 6:27 amWhat am I missing?Code: Select all
>>> t = "win2.s2p" >>> t 'win2.s2p' >>> t.strip(".s2p") 'win'
Code: Select all
$ python3
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> girl = "Dana"
>>> girl.strip("all clothes")
'Dan'
dont_think_twice wrote: ↑Sat Feb 12, 2022 6:41 pmI switched to split last night without understanding why the strip didn’t work.
Code: Select all
''.join(t.split('.s2p'))
Code: Select all
>>> t = "win2.s2p"
>>> t.replace(".s2p","")
'win2'
Code: Select all
>>> t = "win2.s2p"
>>> t[:-4]
'win2'