Can someone tell me how to work with strings in appending?


#1

here is my code:

n = ["Michael", "Lieberman"]
# Add your function here
def join_strings(words):
    result = ""
    for i in range(len(words)):
        result.append(words[i])
    return result
print join_strings(n)

#2

Append doesn't work because you are working on string, not a list.

Instruction says: "Create a function that concatenates strings."
You can concatenate strings simply by adding them. All you need to do is to make changes in this part


#3

This is a good example of how your post should be constructed.

On to the issue at hand.

Strings are immutable data types in python that have their own methods.

So in order to change the value we need to overwrite it at each iteration.

EXAMPLE:

n = ['apples', 'oranges']
final = ''
for item in n:
    final =+ item
print(final)

As you can see I am not trying to edit the string it's self because as I said we cannot do that, but I can assign a new string that is a combination of two other strings.

Another cool trick you can do is using a string method called join you can pass an item that is iteratable and it will join each item into one string.

String Method Join

n = ['apples', 'oranges']
print(' '.join(n)) # What you put inside the quotes will be inserted between each element
# OUTPUT: 'apples oranges'
print('a'.join(n)) # Used a this time
# OUTPUT: 'applesaoranges'

If you still require some help feel free to ask.


#4

HAHAHAHAHAH, thank you, I love you dawdirz87, seriously, thanks so much for answering my question in a straightforward, easy to understand, that empathizes with the confusion of the asker/student, as oppose to others, who answer in a long, awkward, detourying, and not direct, and easy to understand fashion. OMG, thank you so much, apparently this has nothing to do with the type of data stored, as zeziba has led me in the wrong direction with his ambiguous answer. Thank you, if you saw, Codecademy used the word append in their explanations, and that's what led me in the wrong direction. Oh, you can't believe how grateful i am :)heart_eyes: You have a lot to learn, zeziba, from dawidrz87, look how short his answer is, simple, to the point, i understood clearly, and he even explained the concept that i was misunderstanding of concatenates, identifying it very easily. Wow, this is like life giving water, dawidrz87, for a person in a desert. Thank you


#5

zeziba, ur example shows that u didn't detect the source of my confusion, as well as what i was confused with, no offense, u don't have a talent for explaining things to others, if anything, u confused, and drove a student seeking help into madness and despair, which is one of the worst things an educator can do


#6

I have a question for you, if I do all the work for you what do you learn? You can praise whom ever you would like but at the end of the day if you are given the answer what have you truly learned.