How can strings be concatenated?


Question

How to concatenate strings in python?

For example:

Section = 'C_type'

Concatenate it with Sec_ to form the string:

Sec_C_type
1
115
5/23/2018 3:43:35 PM

Accepted Answer

The easiest way would be

Section = 'Sec_' + Section

But for efficiency, see: https://waymoot.org/home/python_string/

179
4/22/2018 1:52:04 AM

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

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon