Discuss / Python / 疑问

疑问

Topic source

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

怎么让中间的空格保留?

def trim(s):
    n = 0
    b = ''
    if isinstance(s,(str)):
        while n <= len(s):
            for a in range(len(s)):
                
                
        
                if s[a] == ' ':
                    n = n + 1
                else :
                    b = b + s[a]
                    n = n + 1
                    c = a
                if b == '':
                    b == None
                
                    
            return b
        
        
    else :
        raise TypeError("I need a 'string'.")

  • 1

Reply