Home  >  Article  >  Backend Development  >  What does python's len function mean?

What does python's len function mean?

coldplay.xixi
coldplay.xixiOriginal
2021-03-05 17:10:4950233browse

Python's len function is used to return the length of strings, lists, dictionaries, tuples, etc. The syntax is [len(str)], where str is the string, list, dictionary, tuple, etc. to be calculated. .

What does python's len function mean?

The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.

The len() function in Python

1: Function: Return the length of string, list, dictionary, tuple, etc.

2: Syntax :

len(str)

3: Parameters:

str: ​​String, list, dictionary, tuple, etc. to be calculated

4: Return value: string, list, dictionary , the length of elements such as tuples

Example

1. Calculate the length of the string:

>>> s = "hello good boy doiido"
>>> len(s)
21

2. Calculate the number of elements in the list:

>>> l = ['h','e','l','l','o']
>>> len(l)
5

Related free learning recommendations: python video tutorial

The above is the detailed content of What does python's len function mean?. 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