Home>Article>Backend Development> How to get the number of set elements in python

How to get the number of set elements in python

(*-*)浩
(*-*)浩 Original
2019-06-29 09:42:47 12617browse

Use python's len() method. The len() method returns the length or number of items of an object (character, list, tuple, etc.).

How to get the number of set elements in python

##len() method syntax:(Recommended learning:Python video tutorial)

len( s )

Parameters

s -- Object.

Return value

Return the length of the object.

Example

The following example shows how len() returns the number of elements of the set:

>>> a = set('abracadabra') >>> len(a) 5 >>>
In this way, you can get the number of elements of the set .


For more Python-related technical articles, please visit the

Python Tutorialcolumn to learn!

The above is the detailed content of How to get the number of set elements in python. 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