简体   繁体   中英

Add value in a variable using for loop - Python Flask

I'm new in python + flask, and having a hard time to add a value beside the variable value. The variable text should be on array value.
text123
area123
testing123
['text
\narea
\ntesting123', 'text
\narea
\ntesting123', 'text
\narea
\ntesting123']

This is my code so far

    text = request.form['title']
    value = "123"
    textarray = []
    for txt in text:
        text4 = text.replace('\r', '<br>')
        output = text4 + value
        textarray.append(output)

    return render_template('index.html', text=textarray)

Thank you for your kind answers

Use text.split() to split the input into words

text = request.form['title']
value = "123"
textarray = [word + value for word in text.split()]

According to your elaboration you need to use split:

text = request.form['title'].split()
value = "123"
textarray = []
for txt in text:
    text4 = txt.replace('\r', '<br>')
    output = text4 + value
    textarray.append(output)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM