Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/00-Python Object and Data Structure Basics/07-Sets and Booleans.ipynb
Views: 648
Set and Booleans
There are two other object types in Python that we should quickly cover: Sets and Booleans.
Sets
Sets are an unordered collection of unique elements. We can construct them by using the set() function. Let's go ahead and make a set to see how it works
Note the curly brackets. This does not indicate a dictionary! Although you can draw analogies as a set being a dictionary with only keys.
We know that a set has only unique entries. So what happens when we try to add something that is already in a set?
Notice how it won't place another 1 there. That's because a set is only concerned with unique elements! We can cast a list with multiple repeat elements to a set to get the unique elements. For example:
Booleans
Python comes with Booleans (with predefined True and False displays that are basically just the integers 1 and 0). It also has a placeholder object called None. Let's walk through a few quick examples of Booleans (we will dive deeper into them later in this course).
We can also use comparison operators to create booleans. We will go over all the comparison operators later on in the course.
We can use None as a placeholder for an object that we don't want to reassign yet:
Thats it! You should now have a basic understanding of Python objects and data structure types. Next, go ahead and do the assessment test!