Combine several small strings into one big string
1 If the merge is a sequence, the fastest way is to use the join() method
>>> parts = ['Is', 'Chicago', 'Not', 'Chicago?'] >>> ' '.join(parts) 'Is Chicago Not Chicago?' >>> ','.join(parts) 'Is,Chicago,Not,Chicago?' >>> ''.join(parts) 'IsChicagoNotChicago?'
2 Just combine a few strings, use "+"
>>> a = 'Is Chicago' >>> b = 'Not Chicago?' >>> a + ' ' + b 'Is Chicago Not Chicago?' >>>
3 simple put together
>>> a = 'Hello' 'World' >>> a 'Hello
4format() function
>>> print('{} {}'.format(a,b)) Is Chicago Not Chicago?
5 or
print(a, b, c, sep=':')
6 Performance Issues