About 20,500,000 results
Open links in new tab
  1. null - python: return, return None, and no return at all -- is there ...

    If any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None, and an explicit return statement should be present at the end of the function (if reachable).

  2. Is there a way to return literally nothing in python?

    To literally return 'nothing' use pass, which basically returns the value None if put in a function (Functions must return a value, so why not 'nothing'). You can do this explicitly and return None yourself though. So either: return(x) pass. or. return(x) return None. will do the trick.

  3. How to prevent Python function from returning None

    Jul 24, 2018 · Python will always return None, if no return is specified at the point of exiting the function call. Your options are: return something else if the condition is not met. ignore the function if it returns None; option 1 (return something else when the condition isn't met):

  4. Returning None in Python 3: A Guide to Returning Nothing

    Nov 26, 2024 · Overall, understanding how to return None in Python 3 is essential for writing clean and readable code, particularly when dealing with functions that do not need to return a value. By using None appropriately, developers can clearly express the absence of a value and improve code clarity.

  5. Python None Keyword - GeeksforGeeks

    Apr 26, 2023 · Assigning a value of None to a variable is one way to reset it to its original, empty state. Example 1: We will check the type of None. Output: Example 2: Declaring a variable as None. Output: Note: If a function does not return anything, it returns None in Python.

  6. Python Return Nothing/Null/None/NaN From Function

    Aug 1, 2023 · In Python, a function returns None implicitly if there is no explicit return statement. However, you can also use the return statement followed by the keyword None to indicate that a function should return no value.

  7. Understanding None in Python: Equivalent of Null - PyTutorial

    Feb 15, 2025 · return None # Return None if target is not found. Handling None properly is essential to avoid errors like AttributeError: 'NoneType' object has no attribute. For example, if you try to call a method on a None object, Python will raise an error. To fix such errors, you can check if a variable is None before performing operations.

  8. When to use the return None statement in Python | sebhastian

    Apr 5, 2023 · When a function has no return statement or just the return keyword without any specific value, then it will return the default value None. Consider the following examples: The function a() in the example returns a specific string value ‘Hello’ back to the caller.

  9. Python Function Return None Without Return Statement

    Sep 15, 2022 · If you don’t explicitly set a return value or you omit the return statement, Python will implicitly return the following default value: None. There are three cases of what a function can return: Case 1 : The function has a return statement that returns an explicit value.

  10. Python return None : Understanding, Usage, and Best Practices

    Apr 16, 2025 · In Python, functions can return None in two ways: explicitly using the return None statement or implicitly when there is no return statement in the function. When a function reaches a return None statement, it immediately stops executing and returns the None value.

  11. Some results have been removed
Refresh