Variables & Variable Types

5 minutes
Share the link to this page
Copied
  Completed

Transcript

Hello, in this video we are going to cover variables and variable types in Python so variable. So what is a variable, and it's essentially a way of storing values in memory. And that's all it is. And you have different types of variables. And that's what we're going to be covering after how we cover the use of one how we would actually create such create one, you simply specify a variable name, don't say, variable, I'm going to call volleyball one, var one, and I'm going to find it a value of 500. So by assigning it a value of 500 white does it make Valmont an integer, an integer is a whole number.

So based on what you assign it, that determines the variable type and this Ico is the assignment operator which say sign whatever Right to the left side. So we have a variable called y one, and we can use it anywhere we want in our code. So let's just print var one, scroll down, click Run. And wait for that to run, execute. And there we go. It says 500.

So let's collect some of the other different variable types. So we have this invite to, and this could be something like 45.68. So this is a floating point number because it has a decimal, and we can print it off as we did last one. I'll leave that just for you create 123 and we could assign a string value to this. So hello world and we could print this off Well, so that's some of the data types. There are other data types of law I lists tuples.

And dictionaries. We'll cover them in more depth very soon. So another thing that you can do is something called multiple assignment. So if I have a ay ay b equals C, and say, my day equal to seven, we've created three variables here, but we've all set them to the value seven. So if you have a bunch of variable that you created, set in the motor, the same value, very useful, placeholder to put in B. Copy, paste this A, B, and C. And now if I click one and as you can see, it's printed out seven because they were all seven That's a really, really cool function of the multiple assignment.

So as we've covered, there are different data types, you have the number, the the number, either integers or floating points, as well. So and there's also Python strings. So let's just go a bit more into Python strings. So if I get rid of actually I'll leave the print. And if I do var three for the Morphe, again, but if Are you want to print just the first page, so we can just put in zero like that. Everything starts at zero and do most of the things in computing, so that will print the first character.

And it's printed Hello. We can also print let's say we want to print multiple characters that we could do this Row before for prints the characters from the first to the fifth place. So if I run this and waiting for it to run as exists printed off the first four characters. So the other thing that we can really do which is pretty cool is is print all the characters starting from a specific character. So, so say we want to print all of them except for the first one. We just did that.

So it starts at the second one. And if we run this as you can see it printed all accounts except for the first box we started at index one, which is equivalent to the second character. So that's it for variables and variable types. We'll be covering more pie fine code and features in other videos, feel free to check them out. Thanks for watching, and I look forward to seeing you in the other demos.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.