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

How to print the values of 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 = "save_user_1@gmail.com"))

Output : (1, ‘save_user_1@gmail.com’)

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

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

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

>Solution :

  1. To get a list as output, use brackets : return [user["id"], user["mail"]]
  2. You can try user.keys() to get the dictionary keys, or user.items() to get both keys and values :
def save_user_1(**user):
    print('user keys', user.keys())
    for key, value in user.items():
        print("key =", key, ", value =", value)
    return user["id"], user["mail"]

print(save_user_1(id = 1, name = "john", mail = "save_user_1@gmail.com"))

output :

user keys dict_keys(['id', 'name', 'mail'])
key = id , value = 1
key = name , value = john
key = mail , value = save_user_1@gmail.com
(1, 'save_user_1@gmail.com')
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