How can strings be concatenated?
How to concatenate strings in python?
For example:
Section = 'C_type'
Concatenate it with Sec_
to form the string:
Sec_C_type
Solution 1:
The easiest way would be
Section = 'Sec_' + Section
But for efficiency, see: https://waymoot.org/home/python_string/
Solution 2:
you can also do this:
section = "C_type"
new_section = "Sec_%s" % section
This allows you not only append, but also insert wherever in the string:
section = "C_type"
new_section = "Sec_%s_blah" % section
Solution 3:
Just a comment, as someone may find it useful - you can concatenate more than one string in one go:
>>> a='rabbit'
>>> b='fox'
>>> print '%s and %s' %(a,b)
rabbit and fox