Strip removing more characters than expected

前端 未结 2 717
太阳男子
太阳男子 2020-12-19 13:25

Can anyone explain what\'s going on here:

s = \'REFPROP-MIX:METHANOL&WATER\'
s.lstrip(\'REFPROP-MIX\')   # this returns \':METHANOL&WATER\' as expect         


        
2条回答
  •  太阳男子
    2020-12-19 13:57

    The method mentioned by @PadraicCunningham is a good workaround for the particular problem as stated.

    Just split by the separating character and select the last value:

    s = 'REFPROP-MIX:METHANOL&WATER'
    res = s.split(':', 1)[-1]  # 'METHANOL&WATER'
    

提交回复
热议问题