【leetcode❤python】 58. Length of Last Word

#-*- coding: UTF-8 -*-
#利用strip函数去掉字符串去除空格(其实是去除两边【左边和右边】空格)
#利用split分离字符串成列表
class Solution(object):
    def lengthOfLastWord(self, s):
        """
        :type s: str
        :rtype: int
        """
        if s==None:return 0
        slist=s.strip().split(' ')
        
        return len(slist[-1])
    
sol=Solution()
print sol.lengthOfLastWord('hello ')

原文地址:https://www.cnblogs.com/kwangeline/p/6059561.html