国产睡熟迷奷白丝护士系列精品,中文色字幕网站,免费h网站在线观看的,亚洲开心激情在线

      <sup id="hb9fh"></sup>
          1. 千鋒教育-做有情懷、有良心、有品質的職業(yè)教育機構

            手機站
            千鋒教育

            千鋒學習站 | 隨時隨地免費學

            千鋒教育

            掃一掃進入千鋒手機站

            領取全套視頻
            千鋒教育

            關注千鋒學習站小程序
            隨時隨地免費學習課程

            當前位置:首頁  >  技術干貨  > 如何用Python創(chuàng)建字典

            如何用Python創(chuàng)建字典

            來源:千鋒教育
            發(fā)布人:xqq
            時間: 2023-07-21 17:02:09 1689930129

            Python 字典將數(shù)據存儲在這對鍵值中。它以一種獨特的方式組織數(shù)據,在這種方式中,某個特定的鍵存在某個特定的值。這是一個可變的數(shù)據結構;它的元素可以在創(chuàng)建后修改。在創(chuàng)建字典之前,我們應該記住以下幾點。

              鍵必須是唯一的,并且必須包含單個值。

              值可以是任何類型,如整數(shù)、列表、元組、字符串等。

              密鑰必須是不可變的。

            創(chuàng)建字典

            字典是使用包含在花括號{}中的多鍵值對創(chuàng)建的,每個鍵都用冒號(:)與其值分開。語法如下。

            語法:

            
            dict1 = {"Name": "James", "Age": 25, "Rollnu": 0090001 }
            

            在上面的字典中,名字、年齡、Rollnu 是不可變對象的鍵,James,25,0090001 是它的值。

            讓我們看看下面的例子。

            示例-

            
            Student = {"Name": "John", "Age": 10, "Result":"Passed","Rollno":"009001"}
            print(type(Student))
            print("printing Employee data .... ")
            print(Student) 
            

            輸出:

            
            printing Employee data .... 
            {'Name': 'John', 'Age': 10, 'Result': 'Passed', 'Rollno': '009001'}
            

            空花括號{}用于創(chuàng)建空字典。我們也可以使用內置的 dict()函數(shù)來創(chuàng)建字典。讓我們理解下面的例子。

            示例-

            
            dict = {}
            print("Empty Dictionary is: ")
            print(dict)
            
            # Creating a Dictionary
            # using the dict() method
            dict1 = dict({1: 'Hello', 2: 'Hi', 3: 'Hey'})
            print("\nCreate Dictionary by using the dict() method : ")
            print(dict1)
            
            # Creating a Dictionary
            # with each item as a Pair
            dict2 = dict([('Devansh', 90014), ('Arun', 90015)])
            print("\nDictionary with each item as a pair: ")
            print(dict2)
            

            輸出:

            Empty Dictionary is: 
            {}
            
            Create Dictionary by using the dict() method : 
            {1: 'Hello', 2: 'Hi', 3: 'Hey'}
            
            Dictionary with each item as a pair: 
            {'Devansh': 90014, 'Arun': 90015}
            

            字典主要用于存儲大量的數(shù)據,我們可以通過它的鍵訪問任何值。

            tags: python教程
            聲明:本站稿件版權均屬千鋒教育所有,未經許可不得擅自轉載。
            10年以上業(yè)內強師集結,手把手帶你蛻變精英
            請您保持通訊暢通,專屬學習老師24小時內將與您1V1溝通
            免費領取
            今日已有369人領取成功
            劉同學 138****2860 剛剛成功領取
            王同學 131****2015 剛剛成功領取
            張同學 133****4652 剛剛成功領取
            李同學 135****8607 剛剛成功領取
            楊同學 132****5667 剛剛成功領取
            岳同學 134****6652 剛剛成功領取
            梁同學 157****2950 剛剛成功領取
            劉同學 189****1015 剛剛成功領取
            張同學 155****4678 剛剛成功領取
            鄒同學 139****2907 剛剛成功領取
            董同學 138****2867 剛剛成功領取
            周同學 136****3602 剛剛成功領取
            相關推薦HOT