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 8852009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:17:47+00:00 2026-06-14T13:17:47+00:00

Consider the following: def funcA(): some process = dynamicVar if dynamicVar == 1: return

  • 0

Consider the following:

    def funcA():
        some process = dynamicVar
        if dynamicVar == 1:
            return dynamicVar
        else:
            print "no dynamicVar"

    def main():
        outcome = funcA()

If the ‘some process’ part results in a 1, the var dynamicVar is passed back as outcome to the main func. If dynamicVar is anything but 1, the routine fails as no arguments are being return.

I could wrap the outcome as a list:

    def funcA():
        outcomeList = []
        some process = dynamicVar
        if dynamicVar == 1:
            outcomeList.append(dynamicVar)
            return outcomeList
        else:
            print "no dynamicVar"
            return outcomeList

    def main():
        outcome = funcA()
        if outcome != []:
            do something using dynamicVar
        else:
            do something else!

or maybe as a dictionary item. Each of the 2 solutions I can think of involve another set of processing in the main / requesting func.

Is this the ‘correct’ way to handle this eventuality? or is there a better way?

What is the proper way of dealing with this. I was particularly thinking about trying to catch try: / except: errors, so in that example the uses are reversed, so something along the lines of:

    def funcA():
        some process = dynamicVar
        if dynamicVar == 1:
            return
        else:
            outcome = "no dynamicVar"
            return outcome 

    def main():
        try:
            funcA()
        except:
            outcome = funcA.dynamicVar 
  • 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-06-14T13:17:48+00:00Added an answer on June 14, 2026 at 1:17 pm

    I believe when you write a function, it’s return value should be clear and expected. You should return what you say you will return. That being said, you can use None as a meaningful return value to indicate that the operation failed or produced no results:

    def doSomething():
        """
        doSomething will return a string value 
        If there is no value available, None will be returned
        """
        if check_something():
            return "a string"
    
        # this is being explicit. If you did not do this,
        # None would still be returned. But it is nice
        # to be verbose so it reads properly with intent.   
        return None
    

    Or you can make sure to always return a default of the same type:

    def doSomething():
        """
        doSomething will return a string value 
        If there is no value available, and empty string 
        will be returned
        """
        if check_something():
            return "a string"
    
        return ""
    

    This handles the case with a bunch of complex conditional tests that eventually just fall through:

    def doSomething():
        if foo:
            if bar:
                if biz:
                    return "value"
        return ""
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following functions: def fact1(n): if n < 2: return 1 else: return
Consider the following code: >>> def default_answer(): ... print Default was required! ... return
Consider the following code: def CalcSomething(a): if CalcSomething._cache.has_key(a): return CalcSomething._cache[a] CalcSomething._cache[a] = ReallyCalc(a) return
Consider the following class: class SquareErrorDistance(object): def __init__(self, dataSample): variance = var(list(dataSample)) if variance
Consider the following code in python: def main(): n = input( ) s =
Consider the following example code class A: def __init__(self, i): self.i = i print("Initializing
Consider the following code: class Base(object): @classmethod def do(cls, a): print cls, a class
Consider the following two trivial models: class Iq def score #Some Irrelevant Code end
Consider the following Scala code: object MainObject { def main(args: Array[String]) { import Integer.{
Consider the following (broken) code: import functools class Foo(object): def __init__(self): def f(a,self,b): print

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.