python | Dictionary Access Items


Python | Dictionary Access Items

Dictionary items is ordered, changeable and does not allow  duplicates


if  You will get Dictionary value , You know that name

In other Data types you used indexing based on retrieve data value, but in dictionary you use key for get the value


Example

       dictionary = {

      "Fname": "neel",

      "Sname": "patel",

      "DOB": 18-12-1999

    }

        print(dictionary['Fname'])


 Output

    neel




You will get Items from another way , using get() Method to get the data from dictionary

Example

       dictionary = {

      "Fname": "neel",

      "Sname": "patel",

      "DOB": 18-12-1999

    }

        print(dictionary.get("Fname"))


 Output

    neel




If you get a Key for specific data value from dictionary

Example

       dictionary = {

      "Fname": "neel",

      "Sname": "patel",

      "DOB": 18-12-1999

    }


        print(dictionary.keys())


 Output

    dict_keys(['Fname', 'Sname', 'DOB'])


Post a Comment (0)
Previous Post Next Post