Home > Backend Development > Python Tutorial > How to access python collections

How to access python collections

爱喝马黛茶的安东尼
Release: 2019-07-10 13:20:35
Original
5579 people have browsed it

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

Related recommendations: "Python Video Tutorial"

We can use the in operator to determine:

Is Bart a classmate in this class?

>>> 'Bart' in s
True
Copy after login

Is Bill a classmate in this class?

>>> 'Bill' in s
False
Copy after login

Is bart a classmate in this class?

>>> 'bart' in s
False
Copy after login

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!

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