Discuss / Python / 如果不考虑用切片,感觉for循环还是好用,能处理字符串中的空格

如果不考虑用切片,感觉for循环还是好用,能处理字符串中的空格

Topic source

落落96897

#1 Created at ... [Delete] [Delete and Lock User]

str3 =' AB C '

zm=''

def trim(s):

    b=''

    for zm in s:

        if zm !=' ':

            b=b+zm

    print(b)

trim(str3)


  • 1

Reply