"" vs. []


what is the difference between when to use "" and when to use []?


"" is an empty string while [] is an empty list. depending on what you need to manipulate you’ll want to create one or the other. it really depends on what you’re trying to do.

def reverse(text):
    s = []
    index = len(text)-1
    while index >= 0:
    return ''.join(s)

here we use an empty list s because we want to .append() the letters of text to the list in reverse order and .join() to convert the list to a string and reach our desired output.
if we want to do the same by using strings, we’ll create an empty string s = ""

def reverse(text):
    s = ""
    index = len(text)-1
    while index >= 0:
        s += text[index]
        index -= 1
    return s

in this example instead of using python list operations join and append we used the python string operation concatenate via the + operator. we started with an empty string s and concatenated [added at the end] the letters of text in reverse order.

hope it made sense and feel free to ask more questions