Skip to player
Skip to main content
Search
Connect
Watch fullscreen
Like
Bookmark
Share
More
Add to Playlist
Report
Variables and DataTypes
Tinashe Matanda
Follow
7 months ago
Category
đ
Learning
Transcript
Display full video transcript
00:00
Hi folks, welcome back. So, previously we've just gotten a chance to play around with
00:07
what the queen state means. So, let's clear this out. Alright. And I'll clear out the
00:14
variables as well. Now, we're going to play around with variables. How can we create variables?
00:22
What are variables? So, a variable is essentially a word or a key that maps out to a certain
00:30
value in memory, right? So, when you're creating your code and so on and you're playing around
00:36
with mathematics maybe or whatever, essentially you're playing around with variables, right?
00:41
You're taking values, you're taking numbers, words and so on and you're distributing them
00:46
around the memory of a computer. And variables allow us to essentially map and access those
00:54
different values. Okay. So, variables essentially they store information, they are a container.
01:00
So, that's what we have an idea of. I'm going to use this hashtag by the way. If you want
01:04
to write notes or comments in your code but you don't want Python to process it as if it's
01:09
code, just put a little hashtag next to it. But nonetheless, let's talk about those variables.
01:15
So, variables, yes, they represent information. They store information. So, let's talk about
01:20
information. How can we store information, right? What kind of information can we store?
01:28
So, we're going to process these in parts with what are known as integers, right?
01:33
Integers. So, when we create an integer, for example, an age can be represented as 26, for example.
01:41
And yes, you need the little equal sign because that's what we use to push a value to a variable.
01:47
So, here I'm initializing a variable age and I'm giving it the value 26. That's an integer,
01:53
right? So, an integer is essentially a whole number, right? So, it's a whole number, right?
02:01
And yes, positives and negatives are like, okay? So, an age can be something like that.
02:09
Bank balance. Yes, variables are one word. That's why I'm using the underscore. Balance is going to be
02:16
equal to negative 5, for example. Do you see that? That's a negative. It's still a integer, okay?
02:24
Then there might be cases where you want to work with partials. These are what we call floats,
02:27
right? A float. A float is basically a decimal point value, okay? So, let's give it an example.
02:37
Maybe perhaps I want to represent pi. That would be 3,1459, da-da-da-da-da, right? That's a float.
02:46
And yes, this is obviously positives and negatives as well. Fair enough? Now, this is in terms of
02:55
numerical values, of course. Then there might be cases where we would like to represent words,
03:00
right? This is what we call a string, right? A string is basically a sequence of characters,
03:10
okay? And take note, strings are normally encapsulated in between quotations. Like previously,
03:16
when we played around with the print statement, you notice that we used the quotes to put around
03:23
the hello world, or hello jack, or hello jones, and so on, right? And there's the example exactly.
03:29
So, what we have here is a string. It's a sequence of characters. They are words, right? So, for example,
03:36
I could have a name and set this to Peter, for example, right? It's okay like that, but it's not
03:42
okay if it is not in quotes, right? You'd actually notice that spider screams in your face because it's
03:48
saying, hey, this is an undefined name, Peter, right? Because take note, if it's not in quotes,
03:54
it's going to be taken as if it is a variable that you already created. So, you might want to put quotes
04:00
around it, right? Like that, okay? I'll just get rid of that finishing one day. Okay, then we have cases
04:11
where we have these things known as booleans. Now, a boolean is a bit odd. So, a boolean is a true or
04:19
false value. Okay? So, for example, I could say is married is equal to false, right? Is equals to false,
04:30
and that's very much it, right? And at some point in time, maybe I want to do something. If someone is
04:35
married, I could just say, if is married, then do this. So, it sort of makes that processing a whole
04:40
lot quicker. It's sort of a question that can be answered quicker as well. So, it's pretty cool,
04:46
right? Now, the question is, how do you access a variable that you created, right? That's a question.
04:56
How do you access a variable you created when accessing a variable that you initialized as proper
05:02
terminology states? So, let's do a little print statement here, right? I'm going to say hello
05:09
in a line of its own, right? And then I'm going to print out a name. You're just going to use the
05:15
variable name without quotes, right? If it's in quotes, it's taken as a string, but without quotes,
05:21
then it will access that particular variable. So, if you're running this, notice how we've created all
05:26
those variables there in our variable explorer. See, notice age is an integer of size 1, which is
05:34
good, and it holds the value 26. Bank balance is also that despite the negative, because again,
05:40
integers are positives and negative values, right? The same is married. Notice how that's a boolean
05:47
that says false. See, name is string, float, spy, and so on and so forth. And yes, we do get our outputs,
05:55
hello, and pt at the bottom. Let me just point out, when it comes to this print statement, we have what
06:03
are known, what is known as formatting tags and concatenation. So, concatenation happens where you
06:09
somewhat combining things together. Like, hello, I can concatenate this with a nice little plus
06:15
and say world, like so, right? So, what we have here is hello, concatenation with world. These are
06:22
two different strings that I'm concatenating, by the way. And if we run these, we can get that output
06:27
of hello world. This is what we know as concatenation, right? The ability to join those things together,
06:35
which is good, right? In the end, you'd actually notice when you build some programs,
06:41
concatenation comes in handy. But I must point out, it's a different case when you're concatenating
06:47
numbers, right? Such as 9 plus 9. 9 plus 9 would not give you 9 and 9, it would give you 18.
06:56
Because those are numbers, right? Those are integers. So, if you have a plus operated on integer
07:01
values, you're going to have it look like that. Unless we sort of have a number A, and we gave
07:09
it a string, see why the quotes are important. And we have a B, and we have a string. See,
07:15
now they are not integers. So, if I actually use the plus operator this time, A plus B, if
07:23
I use the plus operator, I'm not going to get an 18. I'm actually going to get something
07:27
a whole lot different. I'm actually now going to get a 99. Because there's strings, it concatenates.
07:33
So, if you're using the plus operator, where you have two strings, right? You are essentially
07:39
going to get concatenation if you have two strings. If you have two integers, you are going to get
07:45
addition rather than concatenation. Okay? That's what we call concatenation. And there might be a case
07:51
where you want to join two things together. We can use what is known as formatting. Formating happens
07:56
now when there's a variable, and there's a nice little slot where you would like to put
08:00
it in. So, let me put it like this, so it makes sense. We would say, hi, whatever your
08:08
name is, right? Variable name, right? We actually put it in curly braces, like that. And I may
08:15
say, it's nice to meet you. See, notice how our variable, we would like to put it right in
08:22
the middle of a lot of nonsense. So, formatting happens where you do this, but there's a nice
08:27
little if that you have to put in front to basically show and represent that you are performing
08:33
formatting. That's what formatting tags are. So, this little if, and in curly braces, we
08:39
put the actual variable name, which is name of Peter. So, that's why we get that, hi, Peter,
08:45
it is nice to meet you. So, that's sort of the idea when you're working around variables,
08:51
and how you can use variables to perform concatenation as much as formatting for you to display a much
08:57
cleaner and meaner output. Last but not least, let's just talk a little bit about the arithmetics.
09:03
Remember how we performed addition? That's addition. Subtraction, we use the hyphen. Division, we
09:09
use this. And multiplication, we use the asterisk. This is how you can perform basic arithmetics.
09:14
using hyphen. However, with this in mind, there's obviously further mathematical operations that
09:23
we can do, such as exponents, or roots, right? Radical signs, and so on and so forth. For
09:30
us to do this, we cannot do this with the nature of the standard math as it is, but we can use
09:38
a math library. By now you have an idea what a library is. We can use a library to do precision
09:44
precisely that. But we'll be looking at some of those at a later stage. So, for now, let's
09:49
close it right there, and I shall see you guys in the next one. Cheers!
09:53
Thank you!
09:54
Thank you!
Be the first to comment
Add your comment
Recommended
0:51
|
Up next
Former Aide Claims She Was Asked to Make a âHit Listâ For Trump
Veuer
2 years ago
1:08
Muskâs X Is âthe Platform With the Largest Ratio of Misinformation or Disinformationâ Amongst All Social Media Platforms
Veuer
2 years ago
4:50
59 companies that are changing the world: From Tesla to Chobani
Fortune
2 years ago
0:46
3 Things to Know About Coco Gauff's Parents
People
2 years ago
0:35
8 Things to Do in the Morning to Improve Productivity
Martha Stewart Living
2 years ago
1:18
USC vs. Colorado: Can Caleb Williams Earn a New Heisman Moment?
SportsGrid
2 years ago
1:04
Vic Mensa Reveals Celebrity Crush, Biggest Dating Pet Peeve & More on Speed Dating | Billboard News
Billboard
2 years ago
1:09
Hollywood Writers Reach âTentative Agreementâ With Studios After 146 Day Strike
Veuer
2 years ago
1:26
Love is Blind stars admit they're burnt out from social media
Fortune
2 years ago
2:01
NHA Customers in Limbo as Company Faces Potential Merger
SportsGrid
2 years ago
25:53
THR Directors in Focus Conversation With 'Alien: Earth' Creator Noah Hawley & More | THR Video
The Hollywood Reporter
2 weeks ago
4:38
Tampa Bay vs. Carolina: Key Player Insights and Game Odds
SportsGrid
2 hours ago
9:55
Al Oppenheiser, the Chief Engineer Behind the 2026 SUV of the Year: Cadillac Escalade IQ
MotorTrend
7 weeks ago
1:21
Seventh DUI Ends in Momâs Driveway After 40-Minute Chase
ReelzChannel
5 weeks ago
26:11
THR Directors in Focus Conversation With 'Stranger Things' Creators Matt and Ross Duffer | THR Video
The Hollywood Reporter
5 days ago
4:21
Moments That Defined 2025 in Hollywood | THR News Video
The Hollywood Reporter
5 days ago
0:51
Our Grinchy Christmas Cake Bites Will Make Your Heart Grow 3 Sizes
Delish
6 months ago
4:26
TKandz "NOW OR NEVER" Lyrics & Meaning | Genius Verified
Genius
4 weeks ago
25:52
Generating Alpha From Geographic Diversification: Carlyle Global Head Of Wealth
Forbes
3 weeks ago
11:41
Gwyneth Paltrow and Timothée Chalamet Talk Tomato DNA, Tron: Legacy, and Music Recs in the Latest Off the Cuff
Vogue
2 weeks ago
1:58
Top NFL Receiving and Scoring Predictions Breakdown
SportsGrid
3 hours ago
5:47
Sub Urban "Mercuryâ Lyrics & Meaning | Genius Verified
Genius
3 weeks ago
1:22
Autopsy Re-Examined The Last Hours of Whitney Houston â Now Streaming on REELZ+
ReelzChannel
6 weeks ago
1:02:14
Inside GMâs Future: AI Cars, Hands-Free & Eyes Off Driving, and Next-Gen Batteries
MotorTrend
6 weeks ago
1:15:41
Reviving Willow Springs and The Future of LA Car Culture, with Singer's Mazen Fawaz
MotorTrend
6 weeks ago
Be the first to comment