Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
zero or one argument
#5
In [1]: def func(*args):
   ...:     if not args:
   ...:         args = 'default'
   ...:     print(args)
   ...:     

In [2]: func('test')
('test',)

In [3]: func('test', 2)
('test', 2)

In [4]: func()
default
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
zero or one argument - by Skaperen - Oct-14-2017, 12:55 AM
RE: zero or one argument - by metulburr - Oct-14-2017, 01:14 AM
RE: zero or one argument - by Skaperen - Oct-14-2017, 01:55 AM
RE: zero or one argument - by metulburr - Oct-14-2017, 02:45 AM
RE: zero or one argument - by wavic - Oct-14-2017, 08:22 AM
RE: zero or one argument - by gruntfutuk - Oct-14-2017, 11:59 AM
RE: zero or one argument - by buran - Oct-14-2017, 12:28 PM
RE: zero or one argument - by snippsat - Oct-14-2017, 12:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  SyntaxError: positional argument follows keyword argument syd_jat 3 5,929 Mar-03-2020, 08:34 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020