---
title: Looking for a way to return more than one value from a Python function?
description: A python function always returns one value. A value is an object, and a function returns only one value. Since the function returns an object, you decide what that object contains!
image: https://cdn-images-1.medium.com/max/1200/1*qr0hxOjiWryaJV2v8BZv-A.png
---

[Skip to content](https://www.connysoderholm.com/blog/looking-for-a-way-to-return-more-than-one-value-from-a-python-function#main-content)

![Conny-Söderholm](https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg)

- [Home](https://www.connysoderholm.com/)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)

Open main navigation

Close main navigation

- [Home](https://www.connysoderholm.com/)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)

 August 25, 2023

# Looking for a way to return more than one value from a Python function?

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm)

Share: [facebook-f icon](http://www.facebook.com/share.php?u=https://www.connysoderholm.com/blog/looking-for-a-way-to-return-more-than-one-value-from-a-python-function) [linkedin-in icon](http://www.linkedin.com/shareArticle?mini=true&url=https://www.connysoderholm.com/blog/looking-for-a-way-to-return-more-than-one-value-from-a-python-function) [Twitter icon](https://twitter.com/intent/tweet?url=https://www.connysoderholm.com/blog/looking-for-a-way-to-return-more-than-one-value-from-a-python-function) [pinterest-p icon](http://pinterest.com/pin/create/link/?url=https://www.connysoderholm.com/blog/looking-for-a-way-to-return-more-than-one-value-from-a-python-function) [envelope icon](mailto:?body=https://www.connysoderholm.com/blog/looking-for-a-way-to-return-more-than-one-value-from-a-python-function)

To return more than one value from a function in Python is impossible. What do you mean? What are you saying?

A python function *always returns one value*. A value is an object, and a function returns only one value. However, since the function returns an object, you decide what that object contains!

Let’s look at an example. We have a function `my_func` which does one thing; it returns the integer value 1. 

![declaring a function my_func() which returns the integer 1](https://cdn-images-1.medium.com/max/1200/1*qr0hxOjiWryaJV2v8BZv-A.png)

An integer is also an object, in this case a class named `int` which we can check the type of by assigning the return value to a variable `one` and passing it to `type(one)`.

![Checking the type of the return value from the function my_func](https://cdn-images-1.medium.com/max/1200/1*grCn5TCHQ29DGDvkf4uRYA.png)

Okay, but how do I return multiple values in an object? We return an object which can hold multiple objects! Let’s define a function `multiple_values` which returns the integers 1 and 2.

What do you think the return value will be? Returning two integers should give us the type `int` right? Not quite, the object returned is a `tuple`.

![](https://cdn-images-1.medium.com/max/1200/1*EzpgS3rOUmCcA74sDBI6Ew.png)

 Python knows we want to return multiple values, because we actually return a tuple containing two integers from the function! Let’s dive into some Python syntax to explore this further.

### Tuple syntax

Writing parentheses around your values declares a tuple. `my_tuple = (1,2)` gives us a tuple of length two. But, you can also declare a tuple without the parentheses!

`my_other_tuple = 1,2` also gives us a tuple. Returning the values 1,2 from a function means that we are creating a tuple and returning it from the function! 

![](https://cdn-images-1.medium.com/max/1200/1*RHpab5IAuRwT6osoeJpwEg.png)

But why doesn’t it return a tuple when we return just one value? To return a tuple with only one value, we have to write a comma after the value.

![](https://cdn-images-1.medium.com/max/1200/1*QuWSGBEDS1kMhVoxiNLA0g.png)

Next up, we will look at assigning values to our variables (unpacking values) from the tuple.

### Unpacking values from a tuple

We looked at how we could return a tuple from a function, but how do we assign these values to variables? This is done by tuple unpacking.

Unpacking is done the same way as creating a tuple. We write the number of variables that we have to the left instead.

![Unpacking values from a tuple returned by the function multiple_values](https://cdn-images-1.medium.com/max/1200/1*Fo3GBV6_XamYARyC4qWutw.png)

Wait a minute Conny! What happens when we do not know the number of items in a tuple? Good question, we use the asterisk \* unpacking operator.

### The asterisk \* unpacking operator

In the example below, we create a tuple `(1,2,3,4)` and assign it to the variable `my_tuple`. We then unpack it to the variables `one`, `two` and `*the_rest`. Note the asterisk on the variable `the_rest`.

The asterisk tells Python to put all the remaining values in the tuple into a list. You can also unpack `lists` and `dictionaries`!

![Unpacking values from a tuple with the asterisk * operator](https://cdn-images-1.medium.com/max/1200/1*w1y4bp2SteQGCdd-7kqwZw.png)

### Returning a dictionary from your function

You can return a dictionary or any other object from your function. Here, we have a function called `returning_a_dictionary`. We return a dictionary comprising four key-value pairs. 

Assign the dictionary to a variable and you can use it straight away.

![defining a function returning_a_dictionary that returns a dictionary](https://cdn-images-1.medium.com/max/1200/1*ai0TecILpoIx2w2Yjr8cNQ.png)

### Source Code

Source code is available on my [Github](https://github.com/consod/articles/tree/main/Python/Return%20more%20than%20one%20value%20from%20function).

### Conclusion

We looked at how Python returns tuples when specifying values separated by a comma. We learned how to unpack these tuples into variables and also how to handle unpacking of objects of unknown lengths. 

[Python](https://www.connysoderholm.com/blog/tag/python)

## Related posts

[![](https://www.connysoderholm.com/hs-fs/hubfs/Imported_Blog_Media/main-qimg-0f8784c4d1da599e5fa55a6f74f6f7b1.png?height=200&name=main-qimg-0f8784c4d1da599e5fa55a6f74f6f7b1.png)](https://www.connysoderholm.com/blog/how-to-automatically-fill-a-column-with-days-of-the-week-in-excel)

[Excel](https://www.connysoderholm.com/blog/tag/excel)

## [How to automatically fill a column with days of the week in Excel](https://www.connysoderholm.com/blog/how-to-automatically-fill-a-column-with-days-of-the-week-in-excel)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 December 27, 2019

To autofill a column with weekdays in Excel we do not need any shortcuts at all.

[Read more](https://www.connysoderholm.com/blog/how-to-automatically-fill-a-column-with-days-of-the-week-in-excel)

[Python](https://www.connysoderholm.com/blog/tag/python)

## [How to search for files on your computer faster with Python](https://www.connysoderholm.com/blog/search-files-on-your-computer-faster-with-python)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 June 28, 2018

How to search for files on your computer faster with Python When I use the Windows Explorer search...

[Read more](https://www.connysoderholm.com/blog/search-files-on-your-computer-faster-with-python)

[Python](https://www.connysoderholm.com/blog/tag/python), [pypdf2](https://www.connysoderholm.com/blog/tag/pypdf2)

## [Count the number of pages in a PDF file with Python and PyPDF2](https://www.connysoderholm.com/blog/count-the-number-of-pages-in-a-pdf-file-with-python-and-pypdf2)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 August 19, 2020

Counting the number of PDF pages Do you need to count the total number of pages in your pdf files?

[Read more](https://www.connysoderholm.com/blog/count-the-number-of-pages-in-a-pdf-file-with-python-and-pypdf2)

[linkedin-in icon](https://www.linkedin.com/in/connysoderholm) [Follow us on Facebook](https://www.youtube.com/@connysoderholm1473)

- [Home](https://www.connysoderholm.com)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)
- [Privacy Policy](https://www.connysoderholm.com/privacy-policy)
- [Disclaimer](https://www.connysoderholm.com/disclaimer)

---

[![Conny Söderholm Logo](https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg "Conny Söderholm Logo")](http://Conny%20Söderholm)

Copyright © 2026 Conny Söderholm

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Conny Söderholm",
    "url" : "https://www.connysoderholm.com/blog/author/conny-soderholm"
  },
  "dateModified" : "2023-08-25T04:14:09.426Z",
  "datePublished" : "2023-08-25T04:14:09.000Z",
  "headline" : "Looking for a way to return more than one value from a Python function?",
  "image" : [ "https://cdn-images-1.medium.com/max/1200/1*qr0hxOjiWryaJV2v8BZv-A.png" ],
  "mainEntityOfPage" : {
    "@id" : "https://www.connysoderholm.com/blog/looking-for-a-way-to-return-more-than-one-value-from-a-python-function",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg"
    },
    "name" : "Conny Söderholm"
  }
}
```