[PYTHON3]三元操作

[PYTHON3]三元操作

该函数最后一行的if就是三元操作

函数目的:将字符串第生个字母改成大写,如果句子最后没有“.”添加一个“.”做为句子结束。

def correct_sentence(text: str) -> str:

    """

        returns a corrected sentence which starts with a capital letter

        and ends with a dot.

    """

    # your code here

    return text[0].upper() + text[1:] + ("." if not text.endswith(".") else "")

发表回复