成免费的crm,久久国产精品新农夫导航新妓网,恋夜秀场全部视频安卓手机,女校花强奷在线播放A级

Python 字典 Dictionary cmp()方法

Python 字典 Dictionary cmp()方法

Python 字典 DictionaryPython 字典 Dictionary

Python 字典的 cmp() 函數用于比較兩個字典元素。

 

語法

cmp()方法語法:

cmp(dict1, dict2)

 

參數

  • dict1 -- 比較的字典。
  • dict2 -- 比較的字典。

 

返回值

如果兩個字典的元素相同返回0,如果字典dict1大于字典dict2返回1,如果字典dict1小于字典dict2返回-1。

 

實例

以下實例展示了 cmp()函數的使用方法:

 

實例(Python 2.0+)

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
dict1 = {'Name': 'Zara', 'Age': 7};
dict2 = {'Name': 'Mahnaz', 'Age': 27};
dict3 = {'Name': 'Abid', 'Age': 27};
dict4 = {'Name': 'Zara', 'Age': 7};
print "Return Value : %d" %  cmp (dict1, dict2)
print "Return Value : %d" %  cmp (dict2, dict3)
print "Return Value : %d" %  cmp (dict1, dict4)

以上實例輸出結果為:

Return Value : -1
Return Value : 1
Return Value : 0

Python 字典 DictionaryPython 字典 Dictionary

下一節:Python 字典(Dictionary) len()方法

Python 教程

相關文章