Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading