Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill an empty string which has already been created in python

Tags:

python

string

I have created an empty string:

s = ""

how can I append text to it? I know how to append something to a list like:

list.append(something)

but how one can append something to an empty string?

like image 770
Coddy Avatar asked Apr 10 '26 13:04

Coddy


2 Answers

The right name would be to concatenate a string to another, you can do this with the + operator:

s = ""
s = s + "some string"
print s

>>> "some string"
like image 66
Christian Tapia Avatar answered Apr 13 '26 01:04

Christian Tapia


like this:

s += "blabla"

Please note that since strings are immutable, each time you concatenate, a new string object is returned.

like image 26
idish Avatar answered Apr 13 '26 03:04

idish