1 00:00:00,120 --> 00:00:04,800 All right so let's talk about variables and methods. 2 00:00:04,800 --> 00:00:07,920 So to do this we're going to make a new file. 3 00:00:07,920 --> 00:00:12,990 So let's do get it and we're going to call this one script up high because in the last video I told 4 00:00:12,990 --> 00:00:16,860 you we're just going to start building off of these scripts and orders and keep it in one script and 5 00:00:16,860 --> 00:00:18,090 keep it going. 6 00:00:18,090 --> 00:00:20,390 So let's get a script out pie. 7 00:00:20,430 --> 00:00:28,140 We'll do one more shebang here of bean Python 3 and then we're going to go ahead and just fill this 8 00:00:28,140 --> 00:00:28,380 out. 9 00:00:28,380 --> 00:00:36,030 I'm going to drag this over just a little bit so let's put a another common up here and let's call this 10 00:00:36,030 --> 00:00:45,000 variables and methods and let's define a variable so let me show you what a variable looks like and 11 00:00:45,000 --> 00:00:47,720 then we'll define what a variable really is. 12 00:00:47,730 --> 00:00:53,490 So let's start with a quote and you can pick your favorite quote here and we're just going to say something 13 00:00:53,490 --> 00:00:54,490 like. 14 00:00:54,630 --> 00:00:59,100 All is fair in love and war. 15 00:00:59,500 --> 00:00:59,800 OK. 16 00:00:59,830 --> 00:01:05,700 So what's happening here is we are creating a variable of a quote now a variable. 17 00:01:05,710 --> 00:01:09,070 All you can think of a variable is as a place holder. 18 00:01:09,130 --> 00:01:16,900 So instead of typing out all is fair in love and war we can just call this place holder at a later time 19 00:01:16,930 --> 00:01:23,380 and it knows hey I'm going to call this information so it's going to store this information inside of 20 00:01:23,380 --> 00:01:31,420 quote and then later we just call quote and then I'll print it out so we can do something like print 21 00:01:31,990 --> 00:01:36,680 quote and save this and I forgot to ampersand. 22 00:01:36,690 --> 00:01:42,510 So excuse me we're in a close it and let's just run script that pie. 23 00:01:42,520 --> 00:01:42,880 Sorry. 24 00:01:42,880 --> 00:01:45,030 Python 3 script up high. 25 00:01:46,040 --> 00:01:48,700 You can see it says all is fair in love and war. 26 00:01:48,700 --> 00:01:58,250 So if we get at this and add the ampersand now so we defined what was in our variable here which was 27 00:01:58,250 --> 00:02:04,010 this this string right we've talked about strings we put a string here as our quote and we printed the 28 00:02:04,010 --> 00:02:05,000 quote. 29 00:02:05,000 --> 00:02:09,670 So if we didn't put the print in here we just swing and copy this and just delete it. 30 00:02:09,680 --> 00:02:17,900 If we save this and we go to print this now there's nothing telling this to print. 31 00:02:17,930 --> 00:02:24,290 So we have quote and we have a quote stored in our quote variable but nothing instructing it to print 32 00:02:24,740 --> 00:02:27,260 so we can we can leave the print back in there. 33 00:02:27,260 --> 00:02:31,480 Just copy and paste it back and now it'll print that quote. 34 00:02:31,520 --> 00:02:35,480 Now we also have what are called methods. 35 00:02:35,750 --> 00:02:42,110 OK so methods are basically functions that are available for a given object. 36 00:02:42,200 --> 00:02:42,850 OK. 37 00:02:42,950 --> 00:02:46,100 So don't worry too much about that description. 38 00:02:46,110 --> 00:02:49,090 That's very dictionary based description. 39 00:02:49,100 --> 00:02:52,030 Just think about what a method does. 40 00:02:52,040 --> 00:02:54,320 So I'll show you these methods here. 41 00:02:54,320 --> 00:03:00,570 So a method might look something like print quote and then let's say we want to make quote upper. 42 00:03:00,680 --> 00:03:06,800 So in order to make it uppercase all uppercase we're just going to throw in this method of upper. 43 00:03:06,800 --> 00:03:11,390 So we just say dot upper if we were to save that and print it 44 00:03:14,450 --> 00:03:21,050 look now the text is all uppercase and you can make a note in here if you want to say it makes it uppercase 45 00:03:22,010 --> 00:03:23,620 and we can copy this. 46 00:03:23,630 --> 00:03:30,530 Let's just copy this whole line like this and let's paste a couple here so we could also do something 47 00:03:30,530 --> 00:03:40,010 like lower for a lower case or we can do something like title for a title case and we can make notes 48 00:03:40,010 --> 00:03:44,840 here of lower case and title case and we say that. 49 00:03:44,840 --> 00:03:47,990 And when you print it what do you think's gonna happen here. 50 00:03:47,990 --> 00:03:53,780 So we're gonna save all is fair in love and war all is fair in love and war and you can see entitled 51 00:03:53,810 --> 00:04:02,470 Case not perfect is capitalizing the and here and the N and the IS but it does capitalize every first 52 00:04:02,480 --> 00:04:06,100 letter as it's instructed to do here. 53 00:04:06,200 --> 00:04:08,010 So these are methods. 54 00:04:08,300 --> 00:04:10,180 There's also other things that we can do. 55 00:04:10,190 --> 00:04:15,740 We can do something like say we want to get the length of this quote We want to know how many characters 56 00:04:15,740 --> 00:04:23,510 are inside the quote we can do something like print length of quote OK we can just say Save and let's 57 00:04:23,510 --> 00:04:27,570 see what it prints out OK so twenty eight. 58 00:04:28,020 --> 00:04:33,840 Now it's 28 characters completely we are to count this all up including the spaces there's 28 characters 59 00:04:33,840 --> 00:04:34,840 there. 60 00:04:34,980 --> 00:04:39,930 So let's make this a little bit more interesting and let's talk a little bit more more about math and 61 00:04:39,930 --> 00:04:45,040 bring that into it and try to tie this all together with what we've learned so far. 62 00:04:45,300 --> 00:04:47,760 So let's use your name. 63 00:04:47,760 --> 00:04:52,330 Let's define a variable of your name and we're going to set it as a string. 64 00:04:52,500 --> 00:04:55,810 So my name is Heath. 65 00:04:55,920 --> 00:04:58,550 So will this say this is a string right. 66 00:04:59,640 --> 00:05:02,460 And let's also define your age. 67 00:05:02,740 --> 00:05:11,560 Now I'm 30 and we'll say this is what is called an end or an integer OK. 68 00:05:11,570 --> 00:05:12,260 And let's say. 69 00:05:12,260 --> 00:05:18,350 What's your grade point average and my grade point average was three point seven. 70 00:05:18,350 --> 00:05:21,290 And this is what is called a float. 71 00:05:21,290 --> 00:05:23,660 Now what is the difference between an integer and a float. 72 00:05:24,230 --> 00:05:29,150 Well an integer has no decimal point a float does. 73 00:05:29,150 --> 00:05:36,940 So if I was a 30 day or 30 years and twenty seven days I might be thirty point one years old. 74 00:05:36,940 --> 00:05:43,620 Right but if I only define as an integer I say int 30. 75 00:05:43,760 --> 00:05:47,860 Then that's going to define that this number is an integer and nothing else. 76 00:05:47,870 --> 00:05:48,970 Same thing with float. 77 00:05:48,980 --> 00:05:55,610 If we want to have the decimal point there we can float a number and define it as like three point seven. 78 00:05:57,260 --> 00:06:00,670 So let's make more sense of this. 79 00:06:00,830 --> 00:06:15,320 We can print out the integer of my age and we can also print out the integer of my or we could say thirty 80 00:06:15,320 --> 00:06:16,930 point one and let's see what happens. 81 00:06:17,060 --> 00:06:26,800 As we discussed here let's save this and let's just print out those two and look it takes thirty point 82 00:06:26,800 --> 00:06:32,740 one and makes it 30 and it takes Integer Integer age and makes it 30 as well. 83 00:06:32,740 --> 00:06:34,500 Now what if this is thirty point nine. 84 00:06:34,540 --> 00:06:40,160 What you think is going to happen you think it's going around it in fact does not around. 85 00:06:40,360 --> 00:06:44,770 So you could see thirty point nine still came out of thirty down here. 86 00:06:44,770 --> 00:06:48,560 It doesn't matter it just takes us first number when we call an integer. 87 00:06:48,640 --> 00:06:54,930 So make sure that if you ever use integer you know that it does not around so let's build upon this 88 00:06:54,950 --> 00:06:55,800 again. 89 00:06:56,190 --> 00:06:59,340 We could take a string now and let's print out a string. 90 00:06:59,340 --> 00:07:07,180 We could say something like My name is and then you could say plus name. 91 00:07:07,200 --> 00:07:08,920 Make sure you add the space in there right. 92 00:07:09,690 --> 00:07:19,120 And you can also say space and I am space and then let's define an age. 93 00:07:19,120 --> 00:07:23,390 So if we try to put age in here watch what happens. 94 00:07:23,390 --> 00:07:30,460 So we're going to say age and we'll say space years old 95 00:07:33,160 --> 00:07:40,730 and let's save this here like this and I'll give you a second to catch up. 96 00:07:40,760 --> 00:07:46,790 So again we're adding a space space in the beginning space at the end space at the end here just so 97 00:07:46,790 --> 00:07:50,670 that we have the syntax right or else it's going to all bunch up together. 98 00:07:50,780 --> 00:07:59,890 So try to print this out and you could see cannot concatenate a string not integer to string. 99 00:07:59,920 --> 00:08:06,570 So this h here is sitting here as an integer. 100 00:08:06,570 --> 00:08:10,770 You can't concatenate a string with an integer. 101 00:08:10,770 --> 00:08:12,060 So how do we fix that. 102 00:08:12,780 --> 00:08:20,010 Well we can do here is we can actually put this into a string format so we'll just say string of age 103 00:08:20,130 --> 00:08:23,190 something like this and save it. 104 00:08:23,210 --> 00:08:28,130 And now it makes it to a string so similar as we made something into an integer and how we can make 105 00:08:28,130 --> 00:08:29,680 something into a float. 106 00:08:29,750 --> 00:08:31,640 We can also make something into a string. 107 00:08:32,270 --> 00:08:38,240 So if we come through here and we hit Enter you could see now that it works. 108 00:08:38,240 --> 00:08:44,820 My name is Heath and I'm 30 years old so a couple more things to know. 109 00:08:45,370 --> 00:08:51,900 What if we had something like our age and you know we got a year older. 110 00:08:51,910 --> 00:09:02,580 Well we can just say something like age plus equals one and we could say friend our age. 111 00:09:03,160 --> 00:09:04,640 Now watch what happened. 112 00:09:07,800 --> 00:09:11,400 Age is now thirty one even up until that point. 113 00:09:11,580 --> 00:09:12,840 Age has been 30. 114 00:09:12,840 --> 00:09:13,200 Right. 115 00:09:13,200 --> 00:09:16,770 You see age coming through here we're utilizing it in all three places. 116 00:09:16,770 --> 00:09:22,610 Now we print age down here and it's 31 because we have changed what is stored in the variable. 117 00:09:22,620 --> 00:09:30,540 So again the variable here of age we had 30 stored in it up until the instruction is called to add one 118 00:09:30,570 --> 00:09:32,370 plus equals one. 119 00:09:32,370 --> 00:09:37,670 So we're just adding one to this age variable here then it stays 30. 120 00:09:37,680 --> 00:09:46,680 Now it is 31 until we change it again so we can also do something along the lines of birthday equals 121 00:09:46,680 --> 00:09:47,070 1. 122 00:09:47,100 --> 00:09:55,470 So we have a value of birthday and then we could say age plus equals birthday and then you're going 123 00:09:55,470 --> 00:10:02,310 to print your age again and guess how old we're gonna be we're gonna be 32. 124 00:10:03,360 --> 00:10:10,140 So it doesn't matter how you store it you can do the plus equals here or minus equals if you wanted 125 00:10:10,140 --> 00:10:15,960 to take away and you can start incorporating your math into your variables you can incorporate your 126 00:10:15,960 --> 00:10:20,970 variables into your strings and you can start tying this all together. 127 00:10:20,970 --> 00:10:24,830 So if you need to re watch this and to make more sense of it that's absolutely fine. 128 00:10:24,840 --> 00:10:27,190 I'm going to harp one more time on this. 129 00:10:27,210 --> 00:10:29,190 Take good notes. 130 00:10:29,310 --> 00:10:31,560 Practice practice practice. 131 00:10:31,560 --> 00:10:37,650 This is stuff that can get overwhelming very quick but hopefully I'm explaining it slow enough and your 132 00:10:37,980 --> 00:10:42,690 you're getting it if you're not getting it please do re watch the video please take notes in Please 133 00:10:42,690 --> 00:10:44,660 utilize outside resources as well. 134 00:10:44,670 --> 00:10:49,110 I understand that I might not always be the best at teaching a particular subject or sometimes it takes 135 00:10:49,110 --> 00:10:56,190 another person hearing it again from somebody else to see this coding is not necessarily easy but once 136 00:10:56,190 --> 00:10:59,000 it clicks it clicks in a lot of it is just repetition. 137 00:10:59,010 --> 00:11:01,240 So that is it for this video. 138 00:11:01,410 --> 00:11:04,190 We've started to tie everything together now from here. 139 00:11:04,190 --> 00:11:08,250 We're going to move into what are called functions and build upon all of this. 140 00:11:08,460 --> 00:11:11,160 So I'll catch you over in the next video on functions.