Home > Backend Development > Python Tutorial > What is a Python dictionary and how to use a python dictionary

What is a Python dictionary and how to use a python dictionary

Tomorin
Release: 2018-08-13 15:25:15
Original
2150 people have browsed it

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()            # 输出所有值
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template