1.11 Python Basics Part 2 - IP

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *

Already have an account? Sign In »

2 hours 57 minutes
Video Transcription
Hello, everyone. Welcome back to enter the python here on Cyber Eri on demand I, as always in your instructor Joe Perry and you're in lessons. Seven video to In this video we're going to discussing the python data types, lists and dictionaries and our last video. We covered strings and numbers,
so a list in python is essentially just an array of data. It's a storage mechanism
for large amounts of data. So, for example, we might do L. One
the way you define a list. The easiest way to find a list in Python is with square brackets
you could also use.
You also use the list command. I'm personally not a huge fan of doing that
just because there's not usually much of a need for it. It's usually easier to use the square brackets and then just assign your values directly in it.
But either way is functional.
You could see her that I created this list. L won, and now we could
I can clear my street and fix that we can look at what l one contains just by typing on the line or by printing it.
Both of those are gonna work the same way in the interpreter in a Python script. If you were actually right this code down into a document, we would have to use print to get it to print to the screen.
But in the interpreter, you could do either.
So you can see here that this list exists and it holds a bunch of numbers right now. And you may remember, from our four video are four loop video that we can do things like four I in L one
I swear,
and you can see there that that will work just fine. Additionally, you can actually perform a lot of other operations with lists. You can, for example, create two lists
L one and L two
and combine them
very easily to create a single list containing all of those datas. Are all of those data's all of those pieces of data?
Additionally, it's worth noting here that this list contains can contain multiple types of data you can contain multiple times of variable. It doesn't necessarily have to be variables doesn't necessarily have to be strings or numbers. It could be basically anything in python. In fact, you could even have
a list containing other lists and you can see that demonstrated when we use
for it is worth noting that depending on your font, it is actually recommended not to use the lower case letter l as a variable name in general, don't you? Single letter variable names. But the lowercase letter l, as you can see here, actually looks like a one and can make the code confusing to read.
We're not too worried about it right now because we're writing very simple programs, but it is worth noticing.
Anyway, The point here that you can see is this list now contains three lists, each of which contains strings or numbers. It's very easy to do. You can see I created those with one line commands each time. Very, very straightforward. Lister A really powerful tool that you know, a surprising amount of work with
We're gonna spend. Like I said in our previous video, we're gonna spend an entire lesson on lists and module two. For now, we're gonna move on to dictionaries. The last python data type we're gonna be discussing in less than six or less than seven. Rather. Um, I'm mixing up my lessons now, so dictionaries are very similar to lists. They're created in a similar way.
But instead of using square brackets,
we're going to use braces or curly brackets, depending on who you're talking to. But those air braces and calling them curly brackets makes you sound like a 12 year old.
I shouldn't say that on video, but I'm going to so moving on dictionary, one that we've created here is an empty dictionary that has no values.
We can also choose to create it
with with some initial values in it.
The way you the way you create values in a dictionary is as what we call key value pairs much like the way you would with a real dictionary, and you're in your office or your home, where you look for the word that you're trying to find the definition of you find that word in the list, and it will show you the definition next to it. Dictionaries and python operated exactly the same way,
so we can do, for example, for our keys. We might do the string. A is the key for the word
Never know when to stop writing the word banana
and see if we can do,
So here you can see we've created this dictionary with three
key value pairs, and those key value pairs are associated with one another by using a colon. They're separated
from each each key value Paris separated from the other key value pairs by commas the same way that items were separated. It enlists, and we just break that out into each of these individual pairs.
Then, instead of using references like you might with lists which are referenced by index, I actually didn't talk about so I'm glad that I'm glad that we're doing this all in one video, you can reference specific items in lists by using the index number. For example, zero will give you the first item of a list.
One will give you the second because, remember, we index from zero.
If you try and find the index of an item that is not in that list, you'll get an error saying that your index is out of range.
But in dictionaries, you don't address them by using the index in the cell you would list. Instead,
you address things in dictionaries
by using the same square brackets. Do you would if it were a list.
But using the key
here, you can see by giving it the key of a it returned Apple. Because, as you may recall from creative, the dictionary
A is paired to Apple as the key to that value. It works exactly the same way with each of them
very easy to reference. Now it's worth noting that if you try and a reference some key that does not exist in your dictionary, you will get an error, and it's just going to say key error. Five actually think it's gonna be key air
not what I meant to do. There.
We're gonna clear this real fast.
Yeah, So the key area is going to be whatever your input was as the key, and I was just telling you that you're not using a valid key. A lot of times it's gonna be because of the case you need to check and make sure because it is case sensitive.
It could be really any cause. The point is that you're not using the right key for that particular dictionary,
so that is lists and dictionaries in python again. Each of those is going to be the subject of its own lesson. They're incredibly powerful tools again, before him. An astonishing array of operations when I spent a whole bunch of time on those in module to. But for now, you are actually done with lessons. Seven of module one,
which means that you were done with Module one. In our next video, we're gonna perform a summary and review.
I'm gonna talk about what we've learned in this module, and we're gonna prepare for the midterm that is going to be part of your supplemental materials. That is the end of module one. I hope that you have enjoyed learning with me. And I hope you come back for module two,
which should be right next on your list. And I'm very, very excited to start really digging into python code and writing some real programs. As always, I'm your instructor, Joe Perry, and thank you for watching Internet Python here on cyber eri on demand
Up Next