Python 基礎教程
Python 字典(Dictionary) clear() 函數(shù)用于刪除字典內(nèi)所有元素。
clear()方法語法:
dict.clear()
該函數(shù)沒有任何返回值。
以下實例展示了 clear()函數(shù)的使用方法:
#!/usr/bin/python dict = {'Name': 'Zara', 'Age': 7}; print "Start Len : %d" % len(dict) dict.clear() print "End Len : %d" % len(dict)
以上實例輸出結(jié)果為:
Start Len : 2 End Len : 0其他擴展