Skip to playerSkip to main content
  • 7 months ago
Transcript
00:00Hi folks, welcome back. So, previously we've just gotten a chance to play around with
00:07what the queen state means. So, let's clear this out. Alright. And I'll clear out the
00:14variables as well. Now, we're going to play around with variables. How can we create variables?
00:22What are variables? So, a variable is essentially a word or a key that maps out to a certain
00:30value in memory, right? So, when you're creating your code and so on and you're playing around
00:36with mathematics maybe or whatever, essentially you're playing around with variables, right?
00:41You're taking values, you're taking numbers, words and so on and you're distributing them
00:46around the memory of a computer. And variables allow us to essentially map and access those
00:54different values. Okay. So, variables essentially they store information, they are a container.
01:00So, that's what we have an idea of. I'm going to use this hashtag by the way. If you want
01:04to write notes or comments in your code but you don't want Python to process it as if it's
01:09code, just put a little hashtag next to it. But nonetheless, let's talk about those variables.
01:15So, variables, yes, they represent information. They store information. So, let's talk about
01:20information. How can we store information, right? What kind of information can we store?
01:28So, we're going to process these in parts with what are known as integers, right?
01:33Integers. So, when we create an integer, for example, an age can be represented as 26, for example.
01:41And yes, you need the little equal sign because that's what we use to push a value to a variable.
01:47So, here I'm initializing a variable age and I'm giving it the value 26. That's an integer,
01:53right? So, an integer is essentially a whole number, right? So, it's a whole number, right?
02:01And yes, positives and negatives are like, okay? So, an age can be something like that.
02:09Bank balance. Yes, variables are one word. That's why I'm using the underscore. Balance is going to be
02:16equal to negative 5, for example. Do you see that? That's a negative. It's still a integer, okay?
02:24Then there might be cases where you want to work with partials. These are what we call floats,
02:27right? A float. A float is basically a decimal point value, okay? So, let's give it an example.
02:37Maybe perhaps I want to represent pi. That would be 3,1459, da-da-da-da-da, right? That's a float.
02:46And yes, this is obviously positives and negatives as well. Fair enough? Now, this is in terms of
02:55numerical values, of course. Then there might be cases where we would like to represent words,
03:00right? This is what we call a string, right? A string is basically a sequence of characters,
03:10okay? And take note, strings are normally encapsulated in between quotations. Like previously,
03:16when we played around with the print statement, you notice that we used the quotes to put around
03:23the hello world, or hello jack, or hello jones, and so on, right? And there's the example exactly.
03:29So, what we have here is a string. It's a sequence of characters. They are words, right? So, for example,
03:36I could have a name and set this to Peter, for example, right? It's okay like that, but it's not
03:42okay if it is not in quotes, right? You'd actually notice that spider screams in your face because it's
03:48saying, hey, this is an undefined name, Peter, right? Because take note, if it's not in quotes,
03:54it's going to be taken as if it is a variable that you already created. So, you might want to put quotes
04:00around it, right? Like that, okay? I'll just get rid of that finishing one day. Okay, then we have cases
04:11where we have these things known as booleans. Now, a boolean is a bit odd. So, a boolean is a true or
04:19false value. Okay? So, for example, I could say is married is equal to false, right? Is equals to false,
04:30and that's very much it, right? And at some point in time, maybe I want to do something. If someone is
04:35married, I could just say, if is married, then do this. So, it sort of makes that processing a whole
04:40lot quicker. It's sort of a question that can be answered quicker as well. So, it's pretty cool,
04:46right? Now, the question is, how do you access a variable that you created, right? That's a question.
04:56How do you access a variable you created when accessing a variable that you initialized as proper
05:02terminology states? So, let's do a little print statement here, right? I'm going to say hello
05:09in a line of its own, right? And then I'm going to print out a name. You're just going to use the
05:15variable name without quotes, right? If it's in quotes, it's taken as a string, but without quotes,
05:21then it will access that particular variable. So, if you're running this, notice how we've created all
05:26those variables there in our variable explorer. See, notice age is an integer of size 1, which is
05:34good, and it holds the value 26. Bank balance is also that despite the negative, because again,
05:40integers are positives and negative values, right? The same is married. Notice how that's a boolean
05:47that says false. See, name is string, float, spy, and so on and so forth. And yes, we do get our outputs,
05:55hello, and pt at the bottom. Let me just point out, when it comes to this print statement, we have what
06:03are known, what is known as formatting tags and concatenation. So, concatenation happens where you
06:09somewhat combining things together. Like, hello, I can concatenate this with a nice little plus
06:15and say world, like so, right? So, what we have here is hello, concatenation with world. These are
06:22two different strings that I'm concatenating, by the way. And if we run these, we can get that output
06:27of hello world. This is what we know as concatenation, right? The ability to join those things together,
06:35which is good, right? In the end, you'd actually notice when you build some programs,
06:41concatenation comes in handy. But I must point out, it's a different case when you're concatenating
06:47numbers, right? Such as 9 plus 9. 9 plus 9 would not give you 9 and 9, it would give you 18.
06:56Because those are numbers, right? Those are integers. So, if you have a plus operated on integer
07:01values, you're going to have it look like that. Unless we sort of have a number A, and we gave
07:09it a string, see why the quotes are important. And we have a B, and we have a string. See,
07:15now they are not integers. So, if I actually use the plus operator this time, A plus B, if
07:23I use the plus operator, I'm not going to get an 18. I'm actually going to get something
07:27a whole lot different. I'm actually now going to get a 99. Because there's strings, it concatenates.
07:33So, if you're using the plus operator, where you have two strings, right? You are essentially
07:39going to get concatenation if you have two strings. If you have two integers, you are going to get
07:45addition rather than concatenation. Okay? That's what we call concatenation. And there might be a case
07:51where you want to join two things together. We can use what is known as formatting. Formating happens
07:56now when there's a variable, and there's a nice little slot where you would like to put
08:00it in. So, let me put it like this, so it makes sense. We would say, hi, whatever your
08:08name is, right? Variable name, right? We actually put it in curly braces, like that. And I may
08:15say, it's nice to meet you. See, notice how our variable, we would like to put it right in
08:22the middle of a lot of nonsense. So, formatting happens where you do this, but there's a nice
08:27little if that you have to put in front to basically show and represent that you are performing
08:33formatting. That's what formatting tags are. So, this little if, and in curly braces, we
08:39put the actual variable name, which is name of Peter. So, that's why we get that, hi, Peter,
08:45it is nice to meet you. So, that's sort of the idea when you're working around variables,
08:51and how you can use variables to perform concatenation as much as formatting for you to display a much
08:57cleaner and meaner output. Last but not least, let's just talk a little bit about the arithmetics.
09:03Remember how we performed addition? That's addition. Subtraction, we use the hyphen. Division, we
09:09use this. And multiplication, we use the asterisk. This is how you can perform basic arithmetics.
09:14using hyphen. However, with this in mind, there's obviously further mathematical operations that
09:23we can do, such as exponents, or roots, right? Radical signs, and so on and so forth. For
09:30us to do this, we cannot do this with the nature of the standard math as it is, but we can use
09:38a math library. By now you have an idea what a library is. We can use a library to do precision
09:44precisely that. But we'll be looking at some of those at a later stage. So, for now, let's
09:49close it right there, and I shall see you guys in the next one. Cheers!
09:53Thank you!
09:54Thank you!
Be the first to comment
Add your comment

Recommended