Home
Cloud
Big Data
CI
Install
Samples
Java
Ubuntu
Maven
Archive
Python
|
Variables: Sets
Sets
Sets
A set is a collection of ordered unique items. Items in the set need to be of hashable types.
Use braces (
{}
) to create a set.
Use commas to separate items in the set.
x = {0, 1, 2, 3, 2} print(type(x)) # ==> <class 'set'> print(x) # ==> {0, 1, 2, 3} print(x[1]) # ==> TypeError: 'set' object is not subscriptable y = {0} # a set with one item print(y) # ==> {0} z = {x, y, 'a'} # ==> TypeError: unhashable type: 'set'
© 2010-2022
mti
tek