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

How to get the number of set elements in python

(*-*)浩
Release: 2019-07-09 10:23:29
Original
12704 people have browsed it

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

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
>>>
Copy after login
In this way, you can get the number of elements of the set .


For more Python-related technical articles, please visit the

Python Tutorial column 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!

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