Python Language Set: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 7: Line 7:


=Overview=
=Overview=
=Initialization=
Set from a tuple:
<syntaxhighlight lang='py'>
s = set((1, 2, 3))
</syntaxhighlight>
Set from a list:
<syntaxhighlight lang='py'>
s = set([1, 2, 3])
</syntaxhighlight>
Set from a string:
<syntaxhighlight lang='py'>
s = set('ABC')
print(s)  # {'C', 'B', 'A'}
</syntaxhighlight>
=Shallow Copy=
=Shallow Copy=
<syntaxhighlight lang='py'>
<syntaxhighlight lang='py'>

Revision as of 18:59, 28 August 2022

Internal

TODO

Overview

Initialization

Set from a tuple:

s = set((1, 2, 3))

Set from a list:

s = set([1, 2, 3])

Set from a string:

s = set('ABC')
print(s)  # {'C', 'B', 'A'}

Shallow Copy

s = set()
s.add('a')
s2 = s.copy()