[Python] Concatenate string parameters with Python

Discussão em 'Python' iniciado por Stack, Fevereiro 2, 2025.

  1. Stack

    Stack Membro Participativo

    Am trying to implement a concatenation of strings in python, these strings are passed into the function as multiple parameters via a tuple...I just quite can't figure out how to process multiple string parameters and use join method to put a - delimiter between the strings. For example when i pass values I, Love,Python, am expecting to see I-Love-Python.. Check out below

    ##Define a function that takes multiple string arguments
    def concatenate(*args):
    #Got a problem processing the tuple elements and append delimiter - to the end of each word
    #Tried using a set with its add method but it didn't work
    u=len(args)#Get the length of the arguments tuple
    myarray={0}#initialize a new set to length 0
    for k in range(0, u):
    myarray.add(args[k]+"-")#append delimiter for every tuple member
    return myarray

    ##call concatenate with parameters and print
    print(concatenate("I","Love","Python"))

    Continue reading...

Compartilhe esta Página