python 的isdigit()

def is_isbn_or_key(word):

    isbn_or_key='key'
    '''
    isdigit()方法检测字符串是否只由数字组成。
    '''
    if len(word)==13 and word.isdigit():
        isbn_or_key='isbn'

    short_word=word.replace('-','')
    if len(short_word)==10 and short_word.isdigit():
        isbn_or_key='isbn'

    return isbn_or_key

 

posted @ 2020-03-25 13:53  tangqiu  阅读(301)  评论(0编辑  收藏  举报