search
HomeBackend DevelopmentPython TutorialWhat is a Python dictionary and how to use a python dictionary

When you learn python to a certain extent, you naturally need to use the Python dictionary. I have to say that python is an extremely convenient language, no matter when it is VERY POWERFUL Anyone who has learned JavaScript knows that a knowledge point similar to JavaScript is called the jQuery library. In order to facilitate the introduction of Python Dictionary, here is an introduction to what the jQuery library is

jQuery library:

1.jQuery is a JavaScript library.

2.jQuery greatly simplifies JavaScript programming.

3.jQuery is easy to learn.

Introduce 123 points, and derive the Python dictionary from this:

  1. The jQuery library is a place that integrates JavaScript codes that we can use in our daily life. In a folder/website, we reference this library to the page in the early stages of building the web page, and when setting up js, reference a single item and extract the effect we need.

  2. As the name suggests, the js programming effect itself is very large. jQuery is written and saved by others for you, so it is much simpler.

  3. On the premise of learning JavaScript, learning jQuery is not difficult.

Compare and derive the meaning of Python dictionary

  1. The python dictionary is also quoted in the dictionary on the web page Various functions are not programmed by others like jQuery, but written and referenced by ourselves. As for why you need to program yourself, the second point will explain.

  2. The characteristic of Python is that the amount of writing is very small, and the purpose of the jQuery library is to reduce the huge amount of programming in JavaScript. Therefore, the main purpose of the Python dictionary is not to reduce the amount of programming. The amount of programming, but multiple references to the effect, plays a convenient role.

  3. The Python language itself has a very low foundation for programming. The Python dictionary is also a function in the Python language. Therefore, the Python dictionary is in the true sense and easy to learn.

    The following is the code in the editor:


#!/usr/bin/python
# -*- coding: UTF-8 -*- 

dict = {}
dict['one'] = "This is one"
dict[2] = "This is two" 
tinydict = {'name': 'john','code':6734, 'dept': 'sales'} 

print dict['one']             # 输出键为'one' 的值
print dict[2]                # 输出键为 2 的值
print tinydict               # 输出完整的字典
print tinydict.keys()            # 输出所有键
print tinydict.values()            # 输出所有值

Then, the output is:

This is one

This is two

{'dept': 'sales', 'code': 6734, 'name' : 'john'}

['dept', 'code', 'name']

['sales', 6734, ' john']

The above is the detailed content of What is a Python dictionary and how to use a python dictionary. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Python: A Deep Dive into Compilation and InterpretationPython: A Deep Dive into Compilation and InterpretationMay 12, 2025 am 12:14 AM

Pythonusesahybridmodelofcompilationandinterpretation:1)ThePythoninterpretercompilessourcecodeintoplatform-independentbytecode.2)ThePythonVirtualMachine(PVM)thenexecutesthisbytecode,balancingeaseofusewithperformance.

Is Python an interpreted or a compiled language, and why does it matter?Is Python an interpreted or a compiled language, and why does it matter?May 12, 2025 am 12:09 AM

Pythonisbothinterpretedandcompiled.1)It'scompiledtobytecodeforportabilityacrossplatforms.2)Thebytecodeistheninterpreted,allowingfordynamictypingandrapiddevelopment,thoughitmaybeslowerthanfullycompiledlanguages.

For Loop vs While Loop in Python: Key Differences ExplainedFor Loop vs While Loop in Python: Key Differences ExplainedMay 12, 2025 am 12:08 AM

Forloopsareidealwhenyouknowthenumberofiterationsinadvance,whilewhileloopsarebetterforsituationswhereyouneedtoloopuntilaconditionismet.Forloopsaremoreefficientandreadable,suitableforiteratingoversequences,whereaswhileloopsoffermorecontrolandareusefulf

For and While loops: a practical guideFor and While loops: a practical guideMay 12, 2025 am 12:07 AM

Forloopsareusedwhenthenumberofiterationsisknowninadvance,whilewhileloopsareusedwhentheiterationsdependonacondition.1)Forloopsareidealforiteratingoversequenceslikelistsorarrays.2)Whileloopsaresuitableforscenarioswheretheloopcontinuesuntilaspecificcond

Python: Is it Truly Interpreted? Debunking the MythsPython: Is it Truly Interpreted? Debunking the MythsMay 12, 2025 am 12:05 AM

Pythonisnotpurelyinterpreted;itusesahybridapproachofbytecodecompilationandruntimeinterpretation.1)Pythoncompilessourcecodeintobytecode,whichisthenexecutedbythePythonVirtualMachine(PVM).2)Thisprocessallowsforrapiddevelopmentbutcanimpactperformance,req

Python concatenate lists with same elementPython concatenate lists with same elementMay 11, 2025 am 12:08 AM

ToconcatenatelistsinPythonwiththesameelements,use:1)the operatortokeepduplicates,2)asettoremoveduplicates,or3)listcomprehensionforcontroloverduplicates,eachmethodhasdifferentperformanceandorderimplications.

Interpreted vs Compiled Languages: Python's PlaceInterpreted vs Compiled Languages: Python's PlaceMay 11, 2025 am 12:07 AM

Pythonisaninterpretedlanguage,offeringeaseofuseandflexibilitybutfacingperformancelimitationsincriticalapplications.1)InterpretedlanguageslikePythonexecuteline-by-line,allowingimmediatefeedbackandrapidprototyping.2)CompiledlanguageslikeC/C transformt

For and While loops: when do you use each in python?For and While loops: when do you use each in python?May 11, 2025 am 12:05 AM

Useforloopswhenthenumberofiterationsisknowninadvance,andwhileloopswheniterationsdependonacondition.1)Forloopsareidealforsequenceslikelistsorranges.2)Whileloopssuitscenarioswheretheloopcontinuesuntilaspecificconditionismet,usefulforuserinputsoralgorit

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools