Python Sets

Sets are used to store multiple items in one variable. They are one of the four data abstractions, meaning they are used to collect data. They are defined using curly braces and have values inside seperated by commas.

Set items are unordered, unchangeable, and do not allow for duplicate values. This means that you can not use indexing to access set items. Instead, you can use a for loop or other iterative method to access the items. Set items can be of any data type, string, integer, float, boolean, etc.

Sets are not ordered meaning the items do not have a definate order so the order of the items can change. New items are always placed at the end of the set. Set items are not changeable meaning we cannot add, remove, or repplace items after the set has been created. Sets do not allow duplicates so if a set has any duplicates it will skip over it and duplicate values won't get printed.

To find the length of a set, use the len() keyword and pass in the set name as the parameter.

You can convert other data abstractions like lists, dictionaries, and tuples into sets by using the set() function and passing in the data abstraction as a parameter. To check the data type of a object, use the type() function which will print out if the data type is set.

You can use .len() to find the length of a set. Use .add() to add items to the end of the set. To add items from another tuple, use .update in the format tuple_you_are_changing.update(other_tuple). You can remove items by using .remove(item_name), .discard(item_name), .pop() to remove items, and .clear() to clear the entire set.