龙空技术网

python 判等判空

optimusKnight 193

前言:

现时兄弟们对“python 判断为空”大体比较关注,大家都需要学习一些“python 判断为空”的相关文章。那么小编同时在网摘上搜集了一些关于“python 判断为空””的相关文章,希望朋友们能喜欢,同学们一起来了解一下吧!

# -*- coding: utf-8 -*-def isNotEmpty(obj):    # 判断非空    return not isEmpty(obj)def isEmpty(obj):    # 判空    if obj is None:        return True    elif isinstance(obj, str):        if obj is None:            return True        elif obj == "null":            return True        elif obj == "":            return True        elif obj == " ":            return True        else:            return False    elif isinstance(obj, bytes):        if obj == b"":            return True        else:            return False    elif isinstance(obj, list):        if not obj:            return True        else:            return False    elif isinstance(obj, dict):        if not obj:            return True        else:            return False    elif isinstance(obj, tuple):        if not obj:            return True        else:            return False    else:        return Falsedef equals(value1, value2):    # 判等    if value1 is value2:        return True    elif isinstance(value1, bytes) and isinstance(value2, bytes):        if value1 == value2:            return True        else:            return False    elif isinstance(value1, int) and isinstance(value2, int):        if value1 == value2:            return True        else:            return False    elif isinstance(value1, float) and isinstance(value2, float):        if value1 == value2:            return True        else:            return False    elif isinstance(value1, str) and isinstance(value2, str):        if value1 == value2:            return True        elif value1.upper() == value2.upper():            return True        else:            return False    elif isinstance(value1, list) and isinstance(value2, list):        if value1 == value2:            return True        else:            return False    elif isinstance(value1, dict) and isinstance(value2, dict):        if value1 == value2:            return True        else:            return False    elif isinstance(value1, tuple) and isinstance(value2, tuple):        if value1 == value2:            return True        else:            return False    else:        return False

标签: #python 判断为空