Coding

Python Programming Tutorial #1 – Variables and Data Types

  • 00:00:00 hey guys so welcome back today I'm going
  • 00:00:04 to be doing a Python tutorial series so
  • 00:00:07 this is the first episode in the series
  • 00:00:09 kind of an introduction showing you how
  • 00:00:12 to download Python how to install it and
  • 00:00:14 then going into data types and variables
  • 00:00:17 so the first important thing to
  • 00:00:18 understand about the Python programming
  • 00:00:20 language so don't worry if you've ever
  • 00:00:23 program before I'm going to be going
  • 00:00:25 over everything very slowly and in depth
  • 00:00:28 so that you can understand I recommend
  • 00:00:30 that you follow along with everything
  • 00:00:32 I'm doing in the toriel pause the video
  • 00:00:34 at certain points rewind if you don't
  • 00:00:36 understand it's important you understand
  • 00:00:38 these parts so that we can move forward
  • 00:00:39 into more complex ideas so obviously the
  • 00:00:43 first thing that we're going to do if
  • 00:00:45 we're going to learn Python is we have
  • 00:00:46 to install it on our computer so we're
  • 00:00:50 going to go to the python website up
  • 00:00:51 here python org slash downloads right
  • 00:00:54 here and all you're going to do is just
  • 00:00:56 click download Python three point six
  • 00:00:59 point one now I'm not going to do that
  • 00:01:01 because I already have Python installed
  • 00:01:03 and downloaded on my computer but pretty
  • 00:01:06 much once you download this it's going
  • 00:01:08 to pop up down here and your downloads
  • 00:01:09 folder just run the exe it's very simple
  • 00:01:12 and you'll be running Python in no time
  • 00:01:14 so now pause the video go ahead and do
  • 00:01:16 that and then we can go to the next
  • 00:01:17 steps okay so once you've done that
  • 00:01:21 you're going to notice that you have an
  • 00:01:23 application that looks like this it's
  • 00:01:25 called IDL e Python and then it'll have
  • 00:01:28 the version so I'm using version 3.5
  • 00:01:30 don't worry if you have a version that
  • 00:01:33 is large and not so three point six or
  • 00:01:35 even one that's before that most of the
  • 00:01:37 things that I do in this will work in
  • 00:01:39 all the versions of Python okay
  • 00:01:41 so go ahead and run the IDL you'll
  • 00:01:44 notice the first thing that pops up is
  • 00:01:46 the Python shell as you can see at the
  • 00:01:48 top here at the shell now this right
  • 00:01:51 here is not where we're going to write
  • 00:01:53 all our programs
  • 00:01:54 it's the console kind of so here I can
  • 00:01:58 type any lines of code for example I
  • 00:02:00 want to print a name like this and it
  • 00:02:04 will run right away so that's not what
  • 00:02:06 we're going to do you can play around
  • 00:02:07 with this if you want but we're going to
  • 00:02:09 go to file and we're going to click new
  • 00:02:11 file
  • 00:02:13 and then here we go so now we have a new
  • 00:02:16 document that we're going to be working
  • 00:02:18 on in Remy programming so I'm going to
  • 00:02:20 go ahead and I'm going to save this
  • 00:02:21 right away as tutorial 1 into my
  • 00:02:26 tutorial folder which I believe is on my
  • 00:02:28 desktop right here yep right there
  • 00:02:31 awesome okay so there we go we've saved
  • 00:02:34 it and now we're ready to learn a little
  • 00:02:36 bit about datatypes so pretty much
  • 00:02:38 Python is a fairly basic language in
  • 00:02:41 comparison to a lot of other ones a lot
  • 00:02:43 of things that does is a more simple
  • 00:02:45 than other languages but it is important
  • 00:02:47 to understand the basic datatypes so
  • 00:02:49 there's four main data types in Python
  • 00:02:51 there is a few more but we're just going
  • 00:02:53 to talk about these ones right now the
  • 00:02:55 first one is an integer so that can be a
  • 00:02:59 short-form int that stands for integer
  • 00:03:02 now an integer is any number so such as
  • 00:03:05 1 for 76 any whole number it's important
  • 00:03:10 that is a whole number it could be a
  • 00:03:12 negative number as well negative 5 0
  • 00:03:14 those are all integers okay now we have
  • 00:03:18 strings
  • 00:03:19 now if the short-form clear strings is
  • 00:03:22 STR now pretty much a string is anything
  • 00:03:25 embedded in quotations
  • 00:03:27 so like this this my name Tim that is a
  • 00:03:30 string and then we also have something
  • 00:03:31 like this this would be a string and
  • 00:03:35 even like this this would be a string so
  • 00:03:39 although there is a number in here since
  • 00:03:41 it is between these two quotations here
  • 00:03:44 it is a string so even if I did a Mele
  • 00:03:48 number like like that string now it's
  • 00:03:52 also important to understand that it
  • 00:03:53 doesn't matter if you use the single
  • 00:03:55 quotations or the double quotations
  • 00:03:57 sometimes we use the single quotations
  • 00:04:00 because inside of our actual quotations
  • 00:04:02 all you want to use double quotations or
  • 00:04:04 maybe if we use the double quotations
  • 00:04:07 because we want to use the single
  • 00:04:09 quotations inside of our actual string
  • 00:04:11 like that okay so those are just a few
  • 00:04:13 examples now we have boolean variables
  • 00:04:18 or datatype sorry so boolean
  • 00:04:21 datatypes is something like true
  • 00:04:25 and false so true and false pretty basic
  • 00:04:29 these are reserved words in Python
  • 00:04:32 meaning that they're highlighted in
  • 00:04:34 yellow and that you cannot use them for
  • 00:04:36 variable names that's going to be
  • 00:04:37 important later on just know that they
  • 00:04:40 are important words true and false and
  • 00:04:42 they do start with capitals so for
  • 00:04:46 example if I type true like this it's
  • 00:04:48 not highlighting orange right so that's
  • 00:04:50 because true in Python the key word for
  • 00:04:53 that starts with a capital so true and
  • 00:04:55 false then we have the decimals which is
  • 00:05:00 a float data type like this so anything
  • 00:05:03 with a decimal floating point so one
  • 00:05:05 point two three anything like that any
  • 00:05:08 decimal number with a floating decimal
  • 00:05:11 point would be a float okay so those are
  • 00:05:15 the four basic data types there is a few
  • 00:05:20 more that'll go on to later on but you
  • 00:05:22 just have to understand these ones right
  • 00:05:24 now so now that we know these data types
  • 00:05:26 I'll give a quick little quiz here so
  • 00:05:29 I'm just going to put a few things right
  • 00:05:32 here and then I want you to pause the
  • 00:05:39 video and go ahead and try to determine
  • 00:05:40 what type of data type these things are
  • 00:05:46 okay so go ahead pause the video and
  • 00:05:48 then I'll go over the answers in a
  • 00:05:50 second okay so we'll start with the
  • 00:05:53 first one here hello it's the same
  • 00:05:55 example that I have up here except in
  • 00:05:57 single quotations so we can see that it
  • 00:05:59 is a string data type okay so that is
  • 00:06:02 the short-form STR now we have the
  • 00:06:05 number 123 that would be the integer
  • 00:06:08 data type we have another number here
  • 00:06:11 that has a decimal point so 3.2 – that
  • 00:06:14 would be a float we have the keyword
  • 00:06:17 true this data type is a boolean data
  • 00:06:20 type then we have two in quotations this
  • 00:06:24 is very important we don't want to get
  • 00:06:25 this mixed up this is a string some
  • 00:06:28 people may think that it's an integer
  • 00:06:29 because it's two but no it actually is a
  • 00:06:32 string because it is inside of the
  • 00:06:34 quotations and then same thing here
  • 00:06:36 three inside of the double quotations
  • 00:06:38 is a string and not an integer okay so
  • 00:06:41 now that we have an idea of the basic
  • 00:06:43 datatypes I'm going to show you how to
  • 00:06:46 create a variable so pretty much you may
  • 00:06:49 have heard of variables before in math
  • 00:06:51 or something like that
  • 00:06:52 in math we tend to use X as a variable
  • 00:06:55 we say X maybe five X maybe four
  • 00:06:57 anything like that
  • 00:06:59 it's the same thing in Python now
  • 00:07:01 declaring a variable in Python is very
  • 00:07:03 easy all you have to do is type the
  • 00:07:05 variable name so in this case I'm going
  • 00:07:07 to use name and then simply give it a
  • 00:07:10 value so this value as you may remember
  • 00:07:12 is a string this is my name and I'm
  • 00:07:14 destroying it in the variable name now
  • 00:07:18 if I want to access that variable I want
  • 00:07:20 to see what that variable is I can print
  • 00:07:23 it to the console by simply typing the
  • 00:07:26 variable name which is name so now we'll
  • 00:07:29 see what happens if I run the program
  • 00:07:31 it's going to run run module I'm going
  • 00:07:33 to use f5 from now on so that's the
  • 00:07:35 thing and you can see it prints out Tim
  • 00:07:38 just like that okay now say we did that
  • 00:07:42 we have name equals 10 we printed it to
  • 00:07:44 the screen now maybe we want to change
  • 00:07:46 that variable well it's very easy again
  • 00:07:49 all we have to do is just type the value
  • 00:07:51 name and now maybe we going to change it
  • 00:07:53 to Bob and now we want to see what the
  • 00:07:55 new very new variable is so we will
  • 00:07:57 print it to the screen or print name
  • 00:08:00 click f5 to run that and we'll see name
  • 00:08:03 and I are sorry Tim and then Bob so like
  • 00:08:06 we have here name equals Tim print name
  • 00:08:09 name equals Bob print name right
  • 00:08:12 so you set it like that okay so that's
  • 00:08:14 pretty basic um now you can create
  • 00:08:17 variables of different data types so for
  • 00:08:19 example if we had a variable age I would
  • 00:08:22 use an integer data type so like 18 for
  • 00:08:25 that variable and then again if I wanted
  • 00:08:27 to print it to the screen I would say
  • 00:08:28 print and then the variable name like
  • 00:08:31 that
  • 00:08:32 okay 80 perfect right so we printed that
  • 00:08:35 to the screen again if the variable
  • 00:08:39 names there's a few restrictions on
  • 00:08:42 variable names so here you just see I've
  • 00:08:45 used three lowercase letters your
  • 00:08:47 variable names can contain underscore
  • 00:08:51 they cannot contain dashes they can only
  • 00:08:53 contain underscores text and they cannot
  • 00:08:56 start with a number I believe so if I
  • 00:08:58 try to do one one name equals two for
  • 00:09:03 example I run into an invalid syntax
  • 00:09:06 error because we can't name a variable
  • 00:09:09 starting with a number now I can end it
  • 00:09:11 with a number I believe
  • 00:09:13 let's try yep so that's fine it's let us
  • 00:09:19 do that name equals one I could do name
  • 00:09:21 underscore person maybe yeah name
  • 00:09:26 underscore person you see if I run that
  • 00:09:27 program everything's fine there but I
  • 00:09:31 can't put something like a star in my
  • 00:09:34 variable name you see how we've got an
  • 00:09:38 invalid syntax there right this is
  • 00:09:40 because these symbols represent
  • 00:09:41 something else in the Python language so
  • 00:09:44 just know four names we can use capital
  • 00:09:47 as if we'd like I could use name like
  • 00:09:48 that so then the program that works fine
  • 00:09:53 but I cannot start it with numbers so I
  • 00:09:55 cannot put a number there and I cannot
  • 00:09:57 contain anything other than underscores
  • 00:09:59 texts and numbers in or at the end of
  • 00:10:03 the variable name now here's a quiz for
  • 00:10:06 you if I make a variable called name do
  • 00:10:09 another variable called name are they
  • 00:10:13 the same thing now that's a good
  • 00:10:16 question are these two the same thing no
  • 00:10:20 they are not the same thing so capitals
  • 00:10:21 do matter in Python the all capitals
  • 00:10:24 variable name is different than the
  • 00:10:27 variable name so again name like this is
  • 00:10:30 different than all of those variables
  • 00:10:33 there okay so I think I've covered a
  • 00:10:35 little bit on variables and data types
  • 00:10:38 today I'm just to be complete basics
  • 00:10:41 just wanting to get everyone caught up
  • 00:10:43 in the next video we'll go into some
  • 00:10:46 more advanced things maybe operations of
  • 00:10:48 variables adding them together
  • 00:10:50 subtracting multiplying boolean
  • 00:10:53 conditions things like that ok so I hope
  • 00:10:56 you enjoyed the video today stay tuned
  • 00:10:58 and we're going to have another one out
  • 00:11:00 tomorrow and like the video if you
  • 00:11:03 if it was good and subscribe so yeah
  • 00:11:05 thank you