我想從左側寫一個函數條空白字符串。如何在Python中查找字符串中的''3
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()
但我不能引用比較'\'與其他字符串,我試過'''\''',它仍然不起作用。 當字符串是或包含'\'時,如何比較字符串?
提示:看看語法高亮你的問題。 – ApproachingDarknessFish
您需要用'\'來轉義'\'字符,withich會是'temp [0] =='\\'' –
語法爲「丟失結尾報價[']」,這沒有幫助 – Byron