current position:Home>Python from 0 to 1 (day 20) - basic concepts of Python dictionary
Python from 0 to 1 (day 20) - basic concepts of Python dictionary
2022-02-01 10:59:47 【My family】
This is my participation 11 The fourth of the yuegengwen challenge 25 God , Check out the activity details :2021 One last more challenge
The basic concepts of dictionaries
What is a dictionary
The dictionary is Python A common data type in , Used to store data with mapping relationships .
In our daily life , A lot of data " organize a team " appear : Such as book number and book 、 Commodity bar code and name 、 Student and subject scores .....
Each book has its own number , Each item will have its own bar code , Each student has a corresponding subject score ...…. The correspondence between these pairs of data belongs to the mapping relationship .
In short , You can understand the mapping relationship as a corresponding relationship between two data .
Using a dictionary to store these mapped data will be more concise , It's also easier to handle .
Next , I'll teach you to create a dictionary , Look at the grammar in the dictionary first :
We use a curly bracket {} Put these " Pairs of " Enclose the data , Such as : {' The small white ': 90, ' Little black ': 85}, You can define a dictionary .
In the dictionary , these " Pair " The data is called a key value pair , Such as :" The small white ":90 It's a key value pair .
The data in the dictionary is stored in the form of key value pairs , Use English commas between different key value pairs , separate .
The key value pair consists of the key (key) And the value (value) form , Keys and values use English colons : Connect , Key before colon , Value after colon .
In dictionary {' The small white ': 90, ' Little black ': 85} in , Such as name :' The small white ',' Little black ' It belongs to the key , Corresponding results :90,85 It belongs to value .
# Create a dictionary as required , And assign to variable info
info = {' full name ': ' Zhang San ', ' Age ': 22, ' height ': 175.6}
# Print info
print(info)
Copy code
Next , Let's look at the dictionary info, Look at the data types of keys and values in the dictionary ?
info = {
' Personal profile ': (' The small white ', ' male '),
' Hobby ': [' game ', ' The movie '],
' Contact information ': {' Telephone ': 99996666, ' mailbox ': '[email protected]'}
}
Copy code
This dictionary " A little longer ", You can find the value in the dictionary , And say their data types ?
In order to make you observe the dictionary more clearly , I divided it into three lines to write ,:
Of course , Whether it's written in one line or three lines , The dictionary itself has not changed .
You can clearly see the dictionary info in 3 Key value pairs .
First key value pair : ' Personal profile ': (' The small white ', ' male ')
The key is ' Personal profile ', The corresponding value is (' The small white ',' male '), about (' The small white ',' male ') This data type , Do you have any impression ?
This is what we reviewed just now : Tuples .
The second key value pair : ' Hobby ': [' game ', ' The movie ']
The key is ' Hobby ', The corresponding value is [' game ',' The movie '], that [' game ',' The movie '] What data type does it belong to ?
you 're right , This is a list .
The third key value pair : ' Contact information ': {' Telephone ': 99996666, ' mailbox ': '[email protected]'}
The key is ' Contact information ', The corresponding value is ****{' Telephone ': 99996666, ' mailbox ': '[email protected]'}, It's a dictionary .
Tuples , list , A dictionary can also be used as a value in a dictionary .
Let's summarize the data types of keys and values in the dictionary we just explored :
copyright notice
author[My family],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202011059457536.html
The sidebar is recommended
- Python from 0 to 1 (day 14) - Python conditional judgment 1
- Several very interesting modules in Python
- How IOS developers learn Python Programming 15 - object oriented programming 1
- Daily python, Chapter 20, exception handling
- Understand the basis of Python collaboration in a few minutes
- [centos7] how to install and use Python under Linux
- leetcode 1130. Minimum Cost Tree From Leaf Values(python)
- leetcode 1433. Check If a String Can Break Another String(python)
- Python Matplotlib drawing 3D graphics
- Talk about deep and shallow copying in Python
guess what you like
-
Python crawler series - network requests
-
Python thread 01 understanding thread
-
Analysis of earthquake distribution in the past 10 years with Python~
-
You need to master these before learning Python crawlers
-
After the old friend (R & D post) was laid off, I wanted to join the snack bar. I collected some data in Python. It's more or less a intention
-
Python uses redis
-
Python crawler - ETF fund acquisition
-
Detailed tutorial on Python operation Tencent object storage (COS)
-
[Python] comparison of list, tuple, array and bidirectional queue methods
-
Go Python 3 usage and pit Prevention Guide
Random recommended
- Python logging log error and exception exception callback method
- Learn Python quickly and take a shortcut~
- Python from 0 to 1 (day 15) - Python conditional judgment 2
- Python crawler actual combat, requests module, python to capture headlines and take beautiful pictures
- The whole activity collected 8 proxy IP sites to pave the way for the python proxy pool, and the 15th of 120 crawlers
- Why can't list be used as dictionary key value in Python
- Python from 0 to 1 (day 16) - Python conditional judgment 3
- What is the python programming language?
- Python crawler reverse webpack, a real estate management platform login password parameter encryption logic
- Python crawler reverse, a college entrance examination volunteer filling platform encrypts the parameter signsafe and decrypts the returned results
- Python simulated Login, selenium module, python identification graphic verification code to realize automatic login
- Python -- datetime (timedelta class)
- Python's five strange skills will bring you a sense of enrichment in mastering efficient programming skills
- [Python] comparison of dictionary dict, defaultdict and orderdict
- Test driven development using Django
- Face recognition practice: face recognition using Python opencv and deep learning
- leetcode 1610. Maximum Number of Visible Points(python)
- Python thread 03 thread synchronization
- Introduction and internal principles of Python's widely used concurrent processing Library Futures
- Python - progress bar artifact tqdm usage
- Python learning notes - the fifth bullet * class & object oriented
- Python learning notes - the fourth bullet IO operation
- Python crawler actual combat: crawl all the pictures in the answer
- Quick reference manual of common regular expressions, necessary for Python text processing
- [Python] the characteristics of dictionaries and collections and the hash table behind them
- Python crawler - fund information storage
- Python crawler actual combat, pyteseract module, python realizes the visualization of boos direct employment & hook post data
- Pit filling summary: Python memory leak troubleshooting tips
- Python code reading (Chapter 61): delaying function calls
- Through the for loop, compare the differences between Python and Ruby Programming ideas
- leetcode 1606. Find Servers That Handled Most Number of Requests(python)
- leetcode 1611. Minimum One Bit Operations to Make Integers Zero(python)
- 06python learning notes - reading external text data
- [Python] functions, higher-order functions, anonymous functions and function attributes
- Python Networkx practice social network visualization
- Data analysis starts from scratch, and pandas reads and writes CSV data
- Python review (format string)
- [pandas learning notes 01] powerful tool set for analyzing structured data
- leetcode 147. Insertion Sort List(python)
- apache2. 4 + windows deployment Django (multi site)