What does hash do in python?

前端 未结 5 757
春和景丽
春和景丽 2020-11-28 01:31

I saw an example of code that where hash function is applied to a tuple. As a result it returns a negative integer. I wonder what does this function do? Google

5条回答
  •  盖世英雄少女心
    2020-11-28 02:10

    You can use the Dictionary data type in python. It's very very similar to the hash—and it also supports nesting, similar to the to nested hash.

    Example:

    dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
    dict['Age'] = 8; # update existing entry
    dict['School'] = "DPS School" # Add new entry
    
    print ("dict['Age']: ", dict['Age'])
    print ("dict['School']: ", dict['School'])
    

    For more information, please reference this tutorial on the dictionary data type.

提交回复
热议问题