字典.py 450 B

1234567891011121314151617181920
  1. # -*- coding: UTF-8 -*-
  2. print(hash(1))
  3. print(hash(1.1))
  4. print(hash('1'))
  5. print(hash(True))
  6. print(hash(False))
  7. print(hash((1,))) #元组
  8. d1 = {
  9. 1:'整形', ###key在字典中必须唯一,(hash值唯一)
  10. 1.1:'float',
  11. True:'bool', ###hash值为1,这种情况是字典中的key不唯一了。
  12. (3, ): '元组'
  13. }
  14. print(d1)
  15. list7 = ['hello', 'xdc']
  16. print(list7[True]) #hash值为‘1’,所以索引值是1