Playlist : • Py-Pie Python Tutorial
'''
Sets in Python
'''
x = {}
print(type(x))
Sets are unordered.
x = {1,2,3}
y = {3,2,1}
print(x==y)
Set elements are unique. Duplicate elements are not allowed.
x = {1,1,2,3,3,5}
print(x)
A set itself may be modified, but the elements contained in the set must be of an immutable type.
x = {1,2,3}
x[1] = 4
#'set' object does not support item assignment
x ={1,2,3}
#add()
x.add(4)
print(x)
#remove()
x.remove(3)
print(x)
#pop()
x.pop()
print(x)
#clear()
x.clear()
print(x)
#len()
x = {1,2,3}
print(len(x))
x = {1,2,3}
y = list(x)
print(y)
print(1 in x)
print(33 in x)
Frozen Set
x = frozenset({1,2,3})
print(x)
x.add(4)
#frozenset' object has no attribute 'add'
In questa pagina del sito puoi guardare il video online Python Tutorial for Beginners [DataTypes] | Complete set and frozen set tutorial | della durata di ore minuti seconda in buona qualità , che l'utente ha caricato harshal mishra 24 April 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 48 volte e gli è piaciuto 3 spettatori. Buona visione!