Python-实现trim函数
生活随笔
收集整理的這篇文章主要介紹了
Python-实现trim函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-def trim(s):if s[:1] == ' ':return trim(s[1:])if s[-1:] == ' ':return trim(s[:-1])return s# 測試
if trim('hello ') != 'hello':print('測試失敗!')
elif trim(' hello') != 'hello':print('測試失敗!')
elif trim(' hello ') != 'hello':print('測試失敗!')
elif trim(' hello world ') != 'hello world':print('測試失敗!')
elif trim('') != '':print('測試失敗!')
elif trim(' ') != '':print('測試失敗!')
else:print('測試成功!')
?
總結
以上是生活随笔為你收集整理的Python-实现trim函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android话费查询接口,Androi
- 下一篇: maya(学习笔记)之骨骼中关节的轴向确