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
Objects and Data Structures Assessment Test
Test your knowledge. Answer the following questions Write a brief description of all the following Object Types and Data Structures we've learned about: Numbers: Strings: Lists: Tuples: Dictionaries: Numbers Write an equation that uses multiplication, division, an exponent, addition, and subtraction that is equal to 100.25. Hint: This is just to test your memory of … Continue reading Objects and Data Structures Assessment Test
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
Set and Booleans in Python
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 In [1]: x = set() In [2]: # We add to … Continue reading Set and Booleans in Python
Tuples
In Python tuples are very similar to lists, however, unlike lists they are immutable meaning they can not be changed. You would use tuples to present things that shouldn't be changed, such as days of the week, or dates on a calendar. In this section, we will get a brief overview of the following: 1.) … Continue reading Tuples
