简单记录一下

前缀判断

def has_prefix(s, prefix):
    return len(s) >= len(prefix) and s[:len(prefix)] == prefix

后缀判断

def has_suffix(s, suffix):
    return len(s) >= len(suffix) and s[len(s)-len(suffix):] == suffix

包含字符串判断

def contains(s, substr):
    for i, _ in enumerate(s):
        if has_prefix(s[i:], substr):
            return True
    return False
print has_prefix("hello world", 'hello')
print has_suffix("hello world", 'world')
print contains("hello world", "lo")