示例#1
0
 def identify_type(self, string):
     if string.islower():
         return "lower"
     if string.isupper():
         return "upper"
     if string.istitle():
         return "sentence"
     return "wierd"
def hey (string):
    if string.isspace() or string == "":
        return "Fine. Be that way!"
    elif string.isupper():
        return "Whoa, chill out!"
    elif string.endswith("?"):
        return "Sure."
    else:
        return "Whatever."
def hey(string):
    if string.isspace() or string == "":
        return "Fine. Be that way!"
    elif string.isupper():
        return "Whoa, chill out!"
    elif string.endswith("?"):
        return "Sure."
    else:
        return "Whatever."
示例#4
0
def latexSmallCaps(string):
    """Return a string converted to lowercase within a LaTeX smallcaps
    expression (\textsc{}).
    
    """

    if string.isupper():
        return '\\textsc{%s}' % string.lower()
    else:
        return string
示例#5
0
def latexSmallCaps(string):
    """Return a string converted to lowercase within a LaTeX smallcaps
    expression (\textsc{}).
    
    """
    
    if string.isupper():
        return '\\textsc{%s}' % string.lower()
    else:
        return string
def is_num(number):
    """
    判断是否为数字
    :param number:
    :return:
    """
    string = str(number)
    print("判断所有字符都是数字或者字母: ", string.isalnum())
    print("判断所有字符都是字母: ", string.isalpha())
    print("判断所有字符都是数字: ", string.isdecimal())
    print("判断所有字符都是数字: ", string.isnumeric())  # 此方法只针对unicode对象
    print("判断所有字符都是小写: ", string.islower())
    print("判断所有字符都是大写: ", string.isupper())
    print("判断所有字符都是空白符: ", string.isspace())
    return string.isdigit()
示例#7
0
def abbrev_string(string):
    """Abbreviate a string by keeping uppercase and non-alphabetical characters"""
    string_abbrev = ''
    add_next_char = True

    for char in string:
        add_this_char = add_next_char
        if char == ' ':
            add_this_char = False
            add_next_char = True
        elif not char.isalpha():
            add_this_char = True
            add_next_char = True
        elif char.isupper() and not string.isupper():
            add_this_char = True
            add_next_char = False
        else:
            add_next_char = False
        if add_this_char:
            string_abbrev += char

    return string_abbrev
示例#8
0
def isAlphaUpper(string):
    """Return True if string only contains capital letters."""
    return string.isupper() and string.isalpha()