Discuss / Python / 练习一下

练习一下

Topic source

松霜杨雪

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

def trim(str): res = '' con = len(str) if con == 0: return res else: front = 0 behind = 0 while front < con: if str[front] == ' ': front += 1 else: break if front == con: return '' while behind < con: if str[con - behind - 1] == ' ': behind += 1 else: break if behind == 0: return str[front:] else: return str[front:-(behind)]

松霜杨雪

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

才发现,之前定义的res没有用上,多余了……


  • 1

Reply