Files
org_roam/Notes/20250804214537-python_set.org
Zaine ccdd229a7d
All checks were successful
Build Roam Site / build (push) Successful in 32s
search key nav fixes
2026-05-14 14:51:09 +01:00

28 lines
877 B
Org Mode
Executable File

:PROPERTIES:
:ID: 3a41407c-661e-416a-80d2-4c7a137d153a
:END:
#+title: python-set
#+filetags: :python:notes:
Sets are used to store multiple items in a single variable.
Set is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple, and Dictionary, all with different qualities and usage.
A set is a collection which is unordered, unchangeable*, and unindexed.
*Note: Set items are unchangeable, but you can remove items and add new items.
Sets are written with curly brackets.
Example:
#+begin_src python
# Create a Set:
thisset = {"apple", "banana", "cherry"}
print(thisset)
#+end_src
Notes:
Sets are fast, Note that empty Set cannot be created through {}, it creates a dictionary, unless you include values.
set is implemented as a hash table, so you can expect lookup, insert, delete to be O(1) on average.