-4
def func(*args,**kwargs):
    if 'fruit' in args and 'food' in kwargs:
        print('I would like to eat {} {}'.format(args['fruit'], kwargs['food']))

func(fruit='apple',fruit1='banana',food='biryani',dinner='meat')
wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • 3
    You should check what the values of args and kwargs are. – jonrsharpe Sep 26 '21 at 17:45
  • 1
    The problem is, now everything is in `kwargs`. Did you mean: `if 'fruit' in kwargs and 'food' in kwargs:`? – quamrana Sep 26 '21 at 17:47
  • Welcome to Stack Overflow! Please take the [tour] and read [ask]. If this is homework, read [How do I ask and answer homework questions?](https://meta.stackoverflow.com/q/334822/4518341). – wjandrea Sep 26 '21 at 18:24
  • Does this answer your question? [What does \*\* (double star/asterisk) and \* (star/asterisk) do for parameters?](https://stackoverflow.com/questions/36901/what-does-double-star-asterisk-and-star-asterisk-do-for-parameters) – wjandrea Sep 26 '21 at 18:34

1 Answers1

1

*args is used to pass to pass a non-key worded argument list. Try this -

def func(*args,**kwargs):
    if len(args)>0 and 'food' in kwargs:
        print('I would like to eat {} {}'.format(args[0], kwargs['food']))

func('apple',fruit1='banana',food='biryani',dinner='meat')

check out this stackoverflow question for more details on *args and **kwargs.

a11apurva
  • 138
  • 10