python方法items_Python字典items()方法与示例
生活随笔
收集整理的這篇文章主要介紹了
python方法items_Python字典items()方法与示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
python方法items
字典items()方法 (Dictionary items() Method)
items() method is used to get the all items as a view object, the view object represents the key-value pair of the dictionary.
items()方法用于獲取所有項目作為視圖對象,該視圖對象表示字典的鍵值對。
Syntax:
句法:
dictionary_name.items()Parameter(s):
參數:
It does not accept any parameter.
它不接受任何參數。
Return value:
返回值:
The return type of this method is <class 'dict_items'>, it returns the items of the dictionary as view object.
此方法的返回類型為<class'dict_items'> ,它將字典的項目作為視圖對象返回。
Example:
例:
# Python Dictionary items() Method with Example# dictionary declaration student = {"roll_no": 101,"name": "Shivang","course": "B.Tech","perc" : 98.5 }# printing dictionary print("data of student dictionary...") print(student)# printing items print("items of student dictionary...") print(student.items())# printing return type of student.items() Method print("return type is: ", type(student.items()))Output
輸出量
data of student dictionary... {'name': 'Shivang', 'perc': 98.5, 'roll_no': 101, 'course': 'B.Tech'} items of student dictionary... dict_items([('name', 'Shivang'), ('perc', 98.5), ('roll_no', 101), ('course', 'B.Tech')]) return type is: <class 'dict_items'>翻譯自: https://www.includehelp.com/python/dictionary-items-method-with-example.aspx
python方法items
總結
以上是生活随笔為你收集整理的python方法items_Python字典items()方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。