Discuss / Python / 交作业

交作业

Topic source

C❤️M

#1 Created at ... [Delete] [Delete and Lock User]
def trim(s):    if not s:        return s    # 去除左边的空格    left_index = 0    while left_index < len(s) and s[left_index] == ' ':        left_index += 1    # 去除右边的空格    right_index = len(s) - 1    while right_index >= 0 and s[right_index] == ' ':        right_index -= 1    # 返回处理后的字符串    return s[left_index:right_index + 1]

  • 1

Reply