views:

76

answers:

4

Python newbie question

How to concatenate strings in python like

Section = 'C_type'

Concatenate it with 'Sec_' to form the string :

Sec_C_type

+1  A: 

The easiest way would be

Section = 'Sec_' + Section

But for efficiency, see: http://www.skymind.com/~ocrow/python_string/

Mark
A: 

To concatenate strings in python you use the "+" sign

ref: http://www.gidnetwork.com/b-40.html

Steve Robillard
A: 

Use + for string concatenation as:

section = 'C_type'
new_section = 'Sec_' + section
codaddict
A: 

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
pulegium