Home > Article > Backend Development > How to access python collections
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.
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!