Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
zero or one argument
#6
Not to forget the keyword variant:

def something(**kwargs):
    if kwargs:
        for key, value in kwargs.items():
            print(f'{key} is {value}')
    else:
        print('nothing to see here')
            

something()
something(name="fred")
something(place="London", wetness="raining heavily", temp=10)
Which outputs:
nothing to see here
name is fred
place is London
wetness is raining heavily
temp is 10
You don't have to use *args and **kwargs, it is just convention: *mice and **cats, for example, would work. You can use *args and **kwargs in the same call.
I am trying to help you, really, even if it doesn't always seem that way
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 6,008 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