Reputation: 79
I'm working on a project, currently, and I would like to add characters/gr
barfoo = ""
# Something that adds 'hel' to barfoo?
# Something that adds 'lo' to barfoo?
print(barfoo)
> 'hello'
How would I do such a thing? Note that I am aware of adding it to a list and simply 'condensing' it, but I would like to know if there is an easier method.
Upvotes: 0
Views: 9839
Reputation: 1733
Here is an example of what you are trying to achieve:
barfoo = ""
barfoo = barfoo + 'H'
barfoo = barfoo + 'I'
Upvotes: 2
Reputation: 799102
Either start with an empty string and concatenate, or start with an empty list and join.
barfoo = ''
barfoo += 'h'
barfoo += 'i'
print(barfoo)
...
barfoo = []
barfoo.append('h')
barfoo.append('i')
print(''.join(barfoo))
Upvotes: 5