[Python]: Check that no *args. is passed

Question:

Say that I have a function with this signature foo(*args,a:int=0, b_int=1).

How to check if no *args is passed?
I am trying

def foo(*args,a:int=0, b_int=1):
    if args is None:
       print("No args passed")

If I call it with foo(), but I don’t get anything printed on screen.

Asked By: Barzi2001

||

Answers:

In conclusion:
Use not args or args == ()

def foo(*args, a_int=0, b_int=1):
    if not args:
       print("No args passed")
foo()
def foo(*args, a_int=0, b_int=1):
    if args == ():
       print("No args passed")
foo()
Answered By: Nineteendo
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.