What does python's len function mean?

coldplay.xixi
Release: 2023-01-03 09:28:11
Original
50227 people have browsed it

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)
Copy after login

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
Copy after login

2. Calculate the number of elements in the list:

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

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!