In addition to sequence operations and list methods, Python includes a more advanced operation called a list comprehension. List comprehensions allow us to build out lists using a different notation. You can think of it as essentially a one line for loop built inside of brackets. For a simple example: Example 1 In [1]: # Grab … Continue reading List Comprehensions
Category: Uncategorized
Useful Operators
There are a few built-in functions and "operators" in Python that don't fit well into any category, so we will go over them in this lecture, let's begin! range The range function allows you to quickly generate a list of integers, this comes in handy a lot, so take note of how to use it! … Continue reading Useful Operators
while Loops
The while statement in Python is one of most general ways to perform iteration. A while statement will repeatedly execute a single statement or group of statements as long as the condition is true. The reason it is called a 'loop' is because the code statements are looped through over and over again until the … Continue reading while Loops
for Loops
A for loop acts as an iterator in Python; it goes through items that are in a sequence or any other iterable item. Objects that we've learned about that we can iterate over include strings, lists, tuples, and even built-in iterables for dictionaries, such as keys or values. We've already seen the for statement a … Continue reading for Loops
if, elif, else Statements
if Statements in Python allows us to tell the computer to perform alternative actions based on a certain set of results. Verbally, we can imagine we are telling the computer: "Hey if this case happens, perform some action" We can then expand the idea further with elif and else statements, which allow us to tell … Continue reading if, elif, else Statements
Introduction to Python Statements
In this lecture we will be doing a quick overview of Python Statements. This lecture will emphasize differences between Python and other languages such as C++. There are two reasons we take this approach for learning the context of Python Statements: 1.) If you are coming from a different language this will rapidly accelerate your … Continue reading Introduction to Python Statements
Chained Comparison Operators
An interesting feature of Python is the ability to chain multiple comparisons to perform a more complex test. You can use these chained comparisons as shorthand for larger Boolean Expressions. In this lecture we will learn how to chain comparison operators and we will also introduce two other important statements in Python: and and or. … Continue reading Chained Comparison Operators
Comparison Operators
In this lecture we will be learning about Comparison Operators in Python. These operators will allow us to compare variables and output a Boolean value (True or False). If you have any sort of background in Math, these operators should be very straight forward. First we'll present a table of the comparison operators and then … Continue reading Comparison Operators
Files (reading and writing) in Python
Python uses file objects to interact with external files on your computer. These file objects can be any sort of file you have on your computer, whether it be an audio file, a text file, emails, Excel documents, etc. Note: You will probably need to install certain libraries or modules to interact with those various … Continue reading Files (reading and writing) in Python
Booleans in Python(Comparison operators)
For the following quiz questions, we will get a preview of comparison operators. In the table below, a=3 and b=4. Operator Description Example == If the values of two operands are equal, then the condition becomes true. (a == b) is not true. != If values of two operands are not equal, then condition becomes … Continue reading Booleans in Python(Comparison operators)
