Home  >  Article  >  Backend Development  >  How to access python collections

How to access python collections

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-22 10:53:455568browse

How to access python collections? Since set stores an unordered collection, we cannot access it through indexes. Accessing an element in a set is actually determining whether an element is in the set.

How to access python collections

For example, a set that stores the names of classmates:

>>> s = set(['Adam', 'Lisa', 'Bart', 'Paul'])

Related recommendations: "Python Video Tutorial"

We can use the in operator to determine:

Is Bart a classmate in this class?

>>> 'Bart' in s
True

Is Bill a classmate in this class?

>>> 'Bill' in s
False

Is bart a classmate in this class?

>>> 'bart' in s
False

NOTE:

It appears that case matters, 'Bart' and 'bart' are considered two different elements.

The above is the detailed content of How to access python collections. 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