The string passed to strip
is treated as a bunch of characters, not a string. Thus, strip('Axyx')
means "strip occurrences of A
, x
, or y
from either end of the string".
If you actually want to strip a prefix or suffix, you'd have to write that logic yourself. For example:
s = 'Abcd Efgh Axyx'
if s.endswith('Axyx'):
s = s[:-len('Axyx')]