dic = []
if dic:
print("非空 True")
else:
print("空 False")
print("================================")
str1 = ''
if str1:
print("非空 True")
else:
print("空 False")
print("================================")
def func(x):
if not x:
print("传入的参数对象 是一个空的")
return True
print(func(str1))
print("================================")
def function(x):
if x and type(x) is str:
for c in x:
if c == " ":
return True # 字符串中有空格存在 则返回 真
return False
elif x and type(x) is list:
for el in x:
if not el:
return True
return False
elif x and type(x) is tuple:
for el in x:
if not el:
return True
return False
elif not x:
return True
print(function([]))
print(function(["a", "", 3]))
print(function(["a", (1, 2), 3]))