None is often used as a default argument value in Python because it allows us to call the function without providing a value for an argument that isn't required on each function invocation.
You can pass NULL as a function parameter only if the specific parameter is a pointer. The only practical way is with a pointer for a parameter. However, you can also use a void type for parameters, and then check for null, if not check and cast into ordinary or required type.
Setting a parameter's default to None is commonly used when a new mutable object is required. If you set a default to a mutable object (like a list) then that same single object is reused throughout the life of the program. Using None is a pythonic way of indicating that a new object is required.
You can send any data types of argument to a function (string, number, list, dictionary etc.), and it will be treated as the same data type inside the function.
There's nothing wrong with using None to mean "I am not supplying this argument".
You can check for None in your code:
if c is None:
# do something
if d is not None:
# do something else
One recommendation I would make is to have None be the default argument for any optional arguments:
def myfunct(a, b, e, f, c=None, d=None):
# do something
myfunct(A, B, E, F)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With