Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 226881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:33:08+00:00 2026-05-11T19:33:08+00:00

I have a function that has several outputs, all of which native, i.e. integers

  • 0

I have a function that has several outputs, all of which “native”, i.e. integers and strings. For example, let’s say I have a function that analyzes a string, and finds both the number of words and the average length of a word.

In C/C++ I would use @ to pass 2 parameters to the function. In Python I’m not sure what’s the right solution, because integers and strings are not passed by reference but by value (at least this is what I understand from trial-and-error), so the following code won’t work:

def analyze(string, number_of_words, average_length):

    ... do some analysis ...

    number_of_words = ...    
    average_length = ...

If i do the above, the values outside the scope of the function don’t change. What I currently do is use a dictionary like so:

def analyze(string, result):

    ... do some analysis ...

    result['number_of_words'] = ...    
    result['average_length'] = ...

And I use the function like this:

s = "hello goodbye"
result = {}
analyze(s, result)

However, that does not feel right. What’s the correct Pythonian way to achieve this? Please note I’m referring only to cases where the function returns 2-3 results, not tens of results. Also, I’m a complete newbie to Python, so I know I may be missing something trivial here…

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:33:08+00:00Added an answer on May 11, 2026 at 7:33 pm

    python has a return statement, which allows you to do the follwing:

    def func(input):
        # do calculation on input
        return result
    
    s = "hello goodbye"
    res = func(s)       # res now a result dictionary
    

    but you don’t need to have result at all, you can return a few values like so:

    def func(input):
        # do work
        return length, something_else         # one might be an integer another string, etc.
    
    s = "hello goodbye"
    length, something = func(s)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class Foo that has an Update() function, which I want
I have a web service which has a generic function that returns a dataset
If I have a subclass that has yet to implement a function provided by
I have a custom control that has the following prototype. Type.registerNamespace('Demo'); Demo.CustomTextBox = function(element)
I have a function that gets x(a value) and xs(a list) and removes all
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035
I have a function that takes, amongst others, a parameter declared as int privateCount
I have a function that looks like this class NSNode { function insertAfter(NSNode $node)
I have a function that I use called sqlf(), it emulates prepared statements. For
I have a function that is effectively a replacement for print, and I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.