 Welcome back, everyone. Today we're going to talk about variables in Golang. If you like this video, please like and subscribe. It'll help the channel a lot. So last time we were talking about test.go and we made a Hello World program. So I'm going to open that up. So we had a package definition and it's package main. So that was creating our binary. We're importing a library called FMT or format. And then we have our main function and this is where our program actually begins. And then we're using the code from that imported library, so format.println and that prints a line. And then we printed a line called Hello World Digital Forensics Rocks. So we're just going to modify this a little bit. Maybe we want the text to change sometimes. So what we're going to do this time is create something called a variable. And the variable is just a kind of a temporary holder that you can change the contents of. And we're going to create a string variable. So I'm, because I know that my variable is going to be a message, I'm going to call it message. So I'm just going to say message one. And then in Go, when we're creating a new variable, we're going to initialize it with a colon and then equals. And that's basically saying message one is a new variable that equals. And what is it going to equal? Well, we're going to make it equal a string. And I'm just going to put Hello World in here. Okay, so message one equals Hello World. And then if I make another variable called, let's say message two, message two equals, I'm also initializing it with a colon, because it's a new variable. So Hello World two, or sorry, message two, and we'll say digital forensics box. Okay, so now, instead of printing this entire line, I have these two variables that I that I want to print. Okay, and let's say that I still want to print them on the same line. So instead of printing the whole string or writing the whole string out in print line, I can just do MSG one. And then, unlike some other programming languages, Go has a nice feature of just doing concatenation like plus MSG two. Now, think about this for a second, we're doing here message one plus message two. Well, these are strings, they're not numbers, right? So we're not adding two numbers together. Since we can't add strings, what are we doing? Well, we're combining them, we're concatenating them together. Some people might not like this form. And in Go, you can do it a couple different ways. But this is one of the easiest ways. So we'll show you it first. So now I have message one plus message two. Well, what do you expect to happen? Well, hopefully you expect message one to print here and message two to print here. Okay, and then you would see one line with them all together. So let's test it out. If you hit Ctrl O, then you'll save the file, hit Enter to save, and then Ctrl X to get out of it. If we do LS, we need to build the program again, I'll just run test. The old test, this is before. So you can see what it looked like before. Hello, world, exclamation point, space, forensics, rocks, exclamation point. Okay, so then let's build, sorry, go, build, test.go, then run.test again. Okay, so now what's different? We have hello, world, exclamation point, and then no space. And then digital forensics, rocks. Well, why was there no space? Let's go back and look at this for a second. So nano test.go. Okay, so now in here, this is the problem. I don't have any spaces at the beginning of my message to it just literally took hello, world, and then added it with digital forensics, rocks and concatenated them together. Now, what I could do is just add a space at the beginning of this. But if I want to use this message somewhere else, and it's a variable, we probably want to use it many different places, that wouldn't be a very good solution, because it doesn't really, it works for this problem, but it might not work for other problems. Okay, so we don't want to add that space to the beginning. What we can do instead is go to the print line line, and then do plus. And then since we're concatenating strings, we can just do a empty space. So here, what I did is I have my message one plus quotes, which is a empty string or a single space, plus message two. Okay, so now I have added a space in between digital forensics rocks, and I'm going to actually add a couple more spaces just so we can see that this is actually working. Okay, or I'll tell you what, space dash space. Okay, so if you see a dash in the middle, that is this string that we're concatenating in the middle here. So ctrl o, enter, ctrl x, and then I need to build again. So go build test.go, then dot slash test, hello world space dash space digital forensics rocks. Okay, so that's pretty much all there is to assigning variables. Let's go back in. Whenever you're establishing or making a new variable, you need the variable name and make sure it's something that actually makes sense for what it is. Don't just call it, for example, I could have just called this one. I could have just said one equals hello world, something like that. Well, if it's a message, call it message. Try to be as specific as possible for what that variable is holding, because if you're, if you don't have good variable names, whenever you go check your code later, it might be hard to read. In Go, the first time that we're establishing the variable or setting up the variable, we need to use a colon. The second time we do not. So let me show you what that looks like if we don't set the colon at the beginning. So let me build again. Yeah. So command line arguments, undefined message one. So see, whenever we tried to build, we got that error. That message one has a problem. So let's go back. And let's establish it with the semicolon equals. Okay, so now it's already set up. Now, the second time, or you try to use the variable, you don't need to use the colon again, because it's already been kind of created. So let's do message one equals different texts. Okay, so now what I'm doing is I'm setting the variable message one, I'm creating it for the first time and I'm setting it to hello world. Then I set hello message to I'm creating it for the first time and I'm saying digital forensics rocks. Then I'm going back and I'm changing the value of different of message one to different text. So the first time I had a semicolon because I was creating that variable. The second time I don't have the semicolon because it's already created. I'm just changing the value. So now what do we expect to happen? What do we expect to print out if we build this program? So let's go out. See if you can guess what it would be printing out. So dot slash test, different text dash digital forensics rocks. Now notice this doesn't say hello world anymore, because we completely changed everything inside the message one variable. And that's the whole point of variables is that you can change them to whatever you want. In most cases, that's what you want to do. Okay, so whenever you're establishing variables, make sure you use a colon. The second time or any other times after that that you use that variable in go, you don't need to use a colon. Yeah, and that's pretty much it for variables. It might seem a little bit silly, like if you've never used variables before, you might be thinking, why would we ever use these? But this is kind of the core of everything. Variables come in extremely handy later. So just know that a variable is a temporary container that we can put things in and change their values. Okay, so that's it for today. Thank you very much. Thanks for watching. If this was helpful, please like and subscribe. Also, please consider supporting us on Patreon. Your support lets us focus on making better tutorials for everyone.