判断字符是否以某个字符开头和结尾

def check_str(value):
    # 检查你输入的是否是字符类型
    if isinstance(value, str):
        # 判断字符串以什么结尾
        if value.endswith('.sh'):
            return '%s 是以.sh结尾的字符串' % value
        # 判断字符串以什么开头
        elif value.startswith('xi'):
            return '%s 是以xi开头的字符串' % value
        else:
            return '%s 不满足以上条件的字符串' % value
    else:
        return '%s is not str' % value
原文地址:https://www.cnblogs.com/leoych/p/12784427.html