I have the following question: I would like to access the key of a dictionary without accessing its value, for example:
clientes = {'001':{"Nombre":"Juan", "Telefono":"12345", "Direccion":"Calle 1"}}
My question is simple and it is how I access the value "001" to print it or modify it. (I do not want the value that is associated with the key, that is, the name, telephone number and address) but the value of the key itself ("001")
Thank you very much, greetings from Argentina!
Yes you can do it through a
for
:Very simple, you just have to put the name of the key in square brackets after the dictionary.
For example, if you want to get the value of the key
'001'
do the following:Since the result of
clientes['001']
is a dictionary, you can for example access the'Direccion'
like this:This code only works for the case of that dictionary, but if you want to get the name of the key in other situations you must make a for and then check the key match:
The output is: