📜  python删除字符串中间 - Python代码示例

📅  最后修改于: 2022-03-11 14:47:06.376000             🧑  作者: Mango

代码示例1
def remove_middle_character(s):
    h = len(s)//2
    mod = (len(s) + 1) % 2
    return s[:h - mod] + s[h + 1:]

if __name__ == "__main__":
    print(remove_middle_character(""))
    print(remove_middle_character("x"))
    print(remove_middle_character("xy"))
    print(remove_middle_character("apple"))
    print(remove_middle_character("banana"))
    print(remove_middle_character("discount"))