# How to write a function that returns a simple string value

**URL:** <https://discuss.python.org/t/how-to-write-a-function-that-returns-a-simple-string-value/19887>\
**Category:** Python Help\
**Created:** [October 11, 2022, 5:17pm UTC](https://discuss.python.org/t/how-to-write-a-function-that-returns-a-simple-string-value/19887 "2022-10-11T17:17:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Si68](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/si68/32/4672_2.png) [@Si68](https://discuss.python.org/u/Si68)\
**Post date:** [October 11, 2022, 5:17pm UTC](https://discuss.python.org/t/how-to-write-a-function-that-returns-a-simple-string-value/19887/1 "2022-10-11T17:17:49Z")

</div>

Help please. I have to write a simple function that returns a string. The string (in this example) is a city and a country e.g. London, England

I have done some other exercises where I return a formatted name e.g. Bob Johnson, but I cannot get this one right

Here is my codes so far:

```auto
def city_country(city_name, country_name):
	"""Return a string value of information about a city and country."""
	location = f"{city_name} {country_name}"
	return location
	location = city_country('Santiago', 'Chile')
print(city_country)

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![MRAB](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MRAB](https://discuss.python.org/u/MRAB)\
**Post date:** [October 11, 2022, 5:36pm UTC](https://discuss.python.org/t/how-to-write-a-function-that-returns-a-simple-string-value/19887/2 "2022-10-11T17:36:21Z")

</div>

The function is fine, but the line after the `return` statement needs to be indented less, otherwise Python will think that that line is also part of the function.

Then, to print the location, use:

```auto
print(location)

```

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [October 11, 2022, 7:11pm UTC](https://discuss.python.org/t/how-to-write-a-function-that-returns-a-simple-string-value/19887/3 "2022-10-11T19:11:06Z")

</div>

The indent on localation = is too deep.  
Try:

```auto
location = city_country('Santiago', 'Chile')
print(location)

```

---

<div class="post-metadata">

**Author:** ![Si68](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/si68/32/4672_2.png) [@Si68](https://discuss.python.org/u/Si68)\
**Post date:** [October 13, 2022, 4:56pm UTC](https://discuss.python.org/t/how-to-write-a-function-that-returns-a-simple-string-value/19887/4 "2022-10-13T16:56:11Z")

</div>

Thankyou Matthew, sorry for the delay in replying. I’ll give it a go

Regards  
Simon Lock

---

<div class="post-metadata">

**Author:** ![Si68](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/si68/32/4672_2.png) [@Si68](https://discuss.python.org/u/Si68)\
**Post date:** [October 13, 2022, 4:56pm UTC](https://discuss.python.org/t/how-to-write-a-function-that-returns-a-simple-string-value/19887/5 "2022-10-13T16:56:56Z")

</div>

Thankyou for the help Barry, sorry for the delay in replying. I’ll try this out

Regards  
Simon Lock

---

<div class="post-metadata">

**Author:** ![Si68](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/si68/32/4672_2.png) [@Si68](https://discuss.python.org/u/Si68)\
**Post date:** [October 18, 2022, 10:25am UTC](https://discuss.python.org/t/how-to-write-a-function-that-returns-a-simple-string-value/19887/6 "2022-10-18T10:25:29Z")

</div>

That’s worked, thankyou

---

<div class="post-metadata">

**Author:** ![Si68](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/si68/32/4672_2.png) [@Si68](https://discuss.python.org/u/Si68)\
**Post date:** [October 18, 2022, 10:26am UTC](https://discuss.python.org/t/how-to-write-a-function-that-returns-a-simple-string-value/19887/7 "2022-10-18T10:26:35Z")

</div>

That’s working now, thankyou very much
