'How to print the keys here?

I gave some values & keys in a dictionary & showed the value of two keys present here.

def save_user_1(**user):
    return user["id"], user["mail"]

print(save_user_1(id = 1, name = "john", mail = "[email protected]"))

Output : (1, '[email protected]')

1.Why does it show the output as a tuple here?

2.How can I get the values of keys here ?(The oppposite of what showed in the output)



Solution 1:[1]

  1. Because user["id"], user["mail"] is a tuple, same as (user["id"], user["mail"]).
  2. You are getting the values for the keys 'id' and 'mail'. If you want the keys (I'm not sure why you would) you could return [k for k in ('id', 'mail') if k in user].

Solution 2:[2]

When you do return user["id"], user["mail"] you are telling python to return a tuple. Could you add to your question what kind of output you would like from print?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 timgeb
Solution 2 sobek