Python strip() not working inside a function

后端 未结 2 1227
一向
一向 2021-01-29 15:44

I am trying to use strip() to trim off the space before and after a string. It works fine for

str1 = \"  abdced \"
str1.strip()

H

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-29 16:23

    strip is not an in-place method, meaning it returns a value which must be reassigned like so:

    str1 = str1.strip() # the string is reassigned to the returned stripped string
    

提交回复
热议问题