Python字典clear()
方法用於清空(或刪除)字典中的所有資料項目。
語法
以下是clear()
方法的語法 -
dict.clear()
參數
- NA
返回值
- 此方法不返回任何值。
示例
以下示例顯示clear()
方法的用法 -
#!/usr/bin/python3
dict = {'Name': 'Maxsu', 'Age': 7}
print ("Start Len : %d" % len(dict))
dict.clear()
print ("End Len : %d" % len(dict))
當運行上面的程式,它產生以下結果 -
Start Len : 2
End Len : 0
上一篇:
Python字典
下一篇:
Python日期和時間