Home  >  Article  >  Backend Development  >  What is the len method in the python dictionary? What does the len method do?

What is the len method in the python dictionary? What does the len method do?

乌拉乌拉~
乌拉乌拉~Original
2018-08-18 14:07:425564browse

In today's article, we will learn about the built-in functions in the python dictionary. In this article, I will explain the len() method, and len( ) to demonstrate the function. Okay, without further ado, let’s get started with the article.

Description

Python Dictionary (Dictionary) len() function counts the number of dictionary elements, that is, the total number of keys.

Syntax

len() method syntax:

len(dict)

Parameters

dict - - Dictionary whose elements are to be counted.

Return value

Returns the number of elements in the dictionary.

Example

The following example shows how to use the len() function:

#!/usr/bin/python

dict = {'Name': 'Zara', 'Age': 7};
print "Length : %d" % len (dict)

The output result of the above example is:

Length : 2

The above is all the content of this article, the built-in function len() method of the dictionary in python. I hope what I said and the examples I gave can be helpful to you.

For more related knowledge, please visit the Python tutorial column on the php Chinese website.

The above is the detailed content of What is the len method in the python dictionary? What does the len method do?. 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