编写函数fun_connect

img


编写函数fun_connect,输入两个字符串str1,str2,将最后一个字符去掉

def fun_connect(s1, s2):
    retrun s1[:-1]+s2[:-1]


def fun_connext(str1, str2):
    """字符串拼接"""
    print(str1[:-1] + str2[:-1])


str1 = input('输入字符串1: ')
str2 = input('输入字符串2: ')
fun_connext(str1, str2)

有帮助的话,请点采纳该答案~

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 以下回答来自chatgpt:

    是的,我可以提供一个名为fun_connect的函数来实现这个功能。以下是Python代码:

    def fun_connect(str1, str2):
        """
        This function takes in two strings, remove their last character and concatenate them together.
        """
        if len(str1) > 0 and len(str2) > 0:
            return str1[:-1] + str2[:-1]
        else:
            return "Invalid input!"
    

    使用方法:

    str1 = "Hello"
    str2 = "World"
    result = fun_connect(str1, str2)
    print(result) # "HellWorl"
    

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^