• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / How to Return Nothing in Python from Function

How to Return Nothing in Python from Function

June 6, 2022 Leave a Comment

You can return nothing in Python from a function in three ways. The first way is by omitting a return statement.

def someFunction(x):
    x = x * 2

print(someFunction(2))

#Output:
None

The second way is by including a blank return statement.

def someFunction(x):
    x = x * 2
    return

print(someFunction(2))

#Output:
None

The third way is by returning None explicitly.

def someFunction(x):
    x = x * 2
    return None

print(someFunction(2))

#Output:
None

When working with functions in Python, sometimes you don’t want a function to return anything.

In this case, you might be asking, how do I return nothing from a function in Python?

Well, to return nothing, you have three options.

The first way is by omitting a return statement. In this case, you are not returning anything and this returns None.

def someFunction(x):
    x = x * 2

print(someFunction(2))

#Output:
None

The second way is by including a blank return statement. A blank return statement implicitly returns None.

def someFunction(x):
    x = x * 2
    return

print(someFunction(2))

#Output:
None

The third way is by returning None explicitly. By returning None, you can see explicitly that you are getting back None when you call the function.

def someFunction(x):
    x = x * 2
    return None

print(someFunction(2))

#Output:
None

Pick any of these three options and you will succeed with returning nothing from a function in Python.

Hopefully this article has been useful for you to learn how to return nothing in Python.

Other Articles You'll Also Like:

  • 1.  Remove Parentheses from String Using Python
  • 2.  Remove Duplicates from Sorted Array in Python
  • 3.  Return Multiple Values from Function in Python
  • 4.  for char in string – How to Loop Over Characters of String in Python
  • 5.  Check if Character is Letter in Python
  • 6.  Using Python to Read File Character by Character
  • 7.  Python isdigit() Function – Check if Characters in String are Digits
  • 8.  pandas nsmallest – Find Smallest Values in Series or Dataframe
  • 9.  How to Write Excel File to AWS S3 Bucket Using Python
  • 10.  pandas groupby size – Get Number of Elements after Grouping DataFrame

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy