Variables hold information. They're like little drawers with names, holding only one t-shirt, and that t-shirt's name is something. The drawer's name and the t-shirt's 'something' is what you will make.
A variable will look like this:
----------------------
Var = 50
----------------------
Note that, the t-shirt's 'something' is 50. And the drawer's name is Var.
Also note: In Python 3, you don't have to name every variable (or drawer's name) "var". You can name it everything you want. Just make sure you name it something that makes sense. Don't name a variable containing a number, "no_number_var" or something like that. Sure, name it something unique, but name it something useful, and sense-worthy. You can also name it in a shortened version, as in, instead of "a_number_variable", you can name it "num_var".
With this knowledge now siting in your brain, you will be able to do some simple math equations.
Say, you want to add some money (numbers) to your var_account.
Then you can make it happen. I'll write you a simple script so you can get the idea. It should look like this:
----------------------
var_account = 0
var_account += 1
----------------------
What the "+=" means is that you've just added 1 to your var_account. This is the same as typing "var_account = var_account + 1", but it's easier typing it like "+=". It saves time, and makes it easier for you. Although there are some who prefer the longer way... You decide what you want to do.
I still recommend you use the shortcut.
For subtraction (taking out money {subtracting numbers} from your account), type "-=".
Example:
--------------------
var_account = 1
var_account -= 1
--------------------
What this does is, it, well... Subtracts 1 to var_account. Pretty straight forward.
...But maybe you don't want assign a number to a variable. Maybe you want the t-shirt to have a name, its cool brand. Then that brings us to to the second part of the book which I just realized I skipped. Strings.
Strings are assigned to a variable like numbers are, the only thing is, to make a string, a string you have to type it inside these: "".
Example
--------------------
var_string = "T-shirt brand"
--------------------
The t-shirt's something is now a string. It now has a brand, it's own name.
YOU ARE READING
Python 3: Basics
RandomWith this book, you will learn the basics of Python 3. From learning to make a computer print on the screen, "Hello World" to making an RPG, this book will help you learn how to program in Python 3.
