1. 程式人生 > >Python(67)_寫函數,判斷用戶傳入的對象(str,列表,元組)的每一個元素是否有為空,並返回

Python(67)_寫函數,判斷用戶傳入的對象(str,列表,元組)的每一個元素是否有為空,並返回

fun 是否 span pytho png .com print 判斷 分享圖片

#-*-coding:utf-8-*-
‘‘‘
寫函數,判斷用戶傳入的對象(str,列表,元組)的每一個元素是否有為空,並返回
‘‘‘
def func(x):
    ‘‘‘str‘‘‘
    if type(x) is str and x:
        for i in x:
          if i ==  :
              return True
    elif x and type(x) is list or type(x) is tuple:
        for i in  x:
            if not i:
                
return True print(func([1,‘‘,9])) print(func([]))

技術分享圖片

Python(67)_寫函數,判斷用戶傳入的對象(str,列表,元組)的每一個元素是否有為空,並返回