码迷,mamicode.com
首页 > 编程语言 > 详细

[Python] 使用切片处理字符串

时间:2018-02-03 22:03:11      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:==   def   空格   body   pre   trim   处理   turn   class   

要求去除字符串首尾的空格。

def trim(s):
    while s[:1] ==  :
        s = s[1:]
    while s[-1:] ==  :
        s = s[:-1]
    return s

 

[Python] 使用切片处理字符串

标签:==   def   空格   body   pre   trim   处理   turn   class   

原文地址:https://www.cnblogs.com/immjc/p/8410765.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!