[Python] How would I make the output of this for loop into a string, into a variable?

Discussão em 'Python' iniciado por Stack, Maio 10, 2025.

  1. Stack

    Stack Membro Participativo

    In this loop, I'm trying to take user input and continually put it in a list till they write "stop". When the loop is broken, the for loop prints out all of the li's.

    How would I take the output of the for loop and make it a string so that I can load it into a variable?

    x = ([])
    while True:
    item = raw_input('Enter List Text (e.g. <li><a href="#">LIST TEXT</a></li>) (Enter "stop" to end loop):\n')
    if item == 'stop':
    print 'Loop Stopped.'
    break
    else:
    item = make_link(item)
    x.append(item)
    print 'List Item Added\n'


    for i in range(len(x)):
    print '<li>' + x + '</li>\n'


    I want it to end up like this:

    Code:

    print list_output


    Output:

    <li>Blah</li>
    <li>Blah</li>
    <li>etc.</li>

    Continue reading...

Compartilhe esta Página