# Replace string with method argument

**URL:** <https://discuss.python.org/t/replace-string-with-method-argument/10226>\
**Category:** Python Help\
**Tags:** help\
**Created:** [August 19, 2021, 7:21pm UTC](https://discuss.python.org/t/replace-string-with-method-argument/10226 "2021-08-19T19:21:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![srikanth](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@srikanth](https://discuss.python.org/u/srikanth)\
**Post date:** [August 19, 2021, 7:21pm UTC](https://discuss.python.org/t/replace-string-with-method-argument/10226/1 "2021-08-19T19:21:59Z")

</div>

region\_name = ‘test region’  
region\_checked= ‘ReplaceText’  
resp = region\_checked.replace(‘ReplaceText’,‘Region : region\_name’)  
print(resp)

Output I want to see is ‘Region : test region’

How can I get this output.

---

<div class="post-metadata">

**Author:** ![Mholscher](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/mholscher/32/15325_2.png) [@Mholscher](https://discuss.python.org/u/Mholscher)\
**Post date:** [August 19, 2021, 8:19pm UTC](https://discuss.python.org/t/replace-string-with-method-argument/10226/2 "2021-08-19T20:19:23Z")

</div>

> [@srikanth](#):
>
> region\_checked.replace(‘ReplaceText’,‘Region : region\_name’)

As you have written this line, region\_name is part of the string you are outputting. You want the content concatenated to the first part of the string:

```py3
>>> region_name = 'test region'
>>> region_checked= 'ReplaceText'
>>> region_checked.replace('ReplaceText','Region : '+ region_name)
'Region : test region'

```

If it is just about the text output, there are more ways to do what you, e.g. through string formatting:

```auto
>>> 'Region : {}'.format(region_name)
'Region : test region'

```

See [string — Common string operations — Python 3.12.1 documentation](https://docs.python.org/3/library/string.html#format-string-syntax) and the [formatted string literals](https://docs.python.org/3/reference/lexical_analysis.html#formatted-string-literals).

---

<div class="post-metadata">

**Author:** ![srikanth](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@srikanth](https://discuss.python.org/u/srikanth)\
**Post date:** [August 19, 2021, 8:29pm UTC](https://discuss.python.org/t/replace-string-with-method-argument/10226/3 "2021-08-19T20:29:44Z")

</div>

> [@Mholscher](#):
>
> `'Region : {}'.format(region_name)`

Thank you for your reply sir.

---

<div class="post-metadata">

**Author:** ![Olivia21](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/olivia21/32/4630_2.png) [@Olivia21](https://discuss.python.org/u/Olivia21)\
**Post date:** [August 20, 2021, 5:02am UTC](https://discuss.python.org/t/replace-string-with-method-argument/10226/4 "2021-08-20T05:02:32Z")

</div>

Great buddy. I am about to answer but stop my self.
