我试图从左手边写一个功能带空白字符串。
def main():
str_strip = input('enter a string of which whitespace are stripped: ')
cs-strip(str_strip)
def cs-strip(str_strip):
i = 0
temp = list(str_strip)
if temp[0] == ' ':
temp.remove(temp[0])
elif temp[0] == '\' :
if temp[1] == 'n' or temp[1] == 't':
temp.remove(temp[0])
temp.remove(temp[0])
new = ''.join(map(str,temp))
print(new)
main()
但是我无法引用'\'与其他字符串进行比较,我已经尝试过'''\''',但仍然无法正常工作。字符串为“ \”或包含“ \”时,如何比较字符串?
使用'\\'
或r'\'
与反斜杠进行比较,如下所示。
temp[0] == '\\'
temp[0] == r'\'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句