Unmatched Python Function

I need to write a void function that contains three arguments (dictionary, string, string) in python. Obviously python does not have a void function, but is there a way I can make a function in python that acts like a void function in C, C ++ or Java?

+7
python void
source share
2 answers

Since Python is dynamically typed, and you do not specify the type of the return value when defining the function, you can return anything with any type that includes None , which is the return value by default (when you do not return anything, the function actually returns None in bottom of function)

Also a simple return equivalent to return None if you want to do this in the middle of a function.

EDIT: forgot to mention: if you use the yield keyword in a function (even if this line is never executed), the story changes, and this is no longer a normal function, this is a generator ...

+14
source share

You can either add return None to the bottom of the function, or simply omit the return .

+4
source share

All Articles