Main Concept: Saving multiple elements and manipulating variables
Here are a few things that can help you understand the Main Concept for todays lesson:
1. Lists
2. List Indexing
3. String Indexing/Slicing
4. String/List Methods
By the end you will be able to: Store a variety of elements inside of one variable, know how to get certain elements out, and how to manipulate strings/lists.
1. Lists
Just like we can store single values inside of variables, like a single whole number in an int or a sentence in a string, it would be useful for us to be able to store multiple values inside of one variable so that we don’t have to keep track of so many individual items. In order to store multiple items inside of one variable, one method we can use is a list.
A list allows us to store several items in it rather than just one. Lets say we want to keep track of students grades, here’s two ways we could do it:
Above, the variable student_grades is a list of values. That list of values contains [95,87,100]
This saves us time, and allows us to organize the information in our code a little bit more clearly.
2. List Indexing
So now that we know how to make a list, we have to be able to get values out of it in order to use it properly. We calling getting values out of a list indexing.
In order to index into a list we use square brackets ‘[‘ ‘]’. See examples below:
3. String Indexing/Slicing
Similar to how we can index lists, we can use the same thing to strings. You can think of a string as a list of characters. Put simply, a string is just a sequence of characters all combined. For example:
To get only certain characters out of a string, we can index the string and get single characters, or substrings out. Substring meaning a part of a string.
Lets look at the following example:
4. String/List Methods
In Python, we have some control over how we can change strings and lists. We can use things called methods to help us. Lets check out the following example:
Last Lessons Content
Main Concept: Dealing with strings and print formatting.
By the end you will be able to: Understand how strings are simply sequences of characters, how to do unique things with them, and how to print them in nice ways.
Last Lessons Content
Next Lessons Content
Main Concept: Dealing with strings and print formatting.
By the end you will be able to: Understand how strings are simply sequences of characters, how to do unique things with them, and how to print them in nice ways.
Main Concept: Understanding loops and an introduction to libraries.
By the end you will be able to: Understand what a boolean value is and why it is used, and also what loops do in Python and how they help to save time writing code and make it more efficient.