Today, I will talk about variables in a programming language. Before you begin reading this post make a coffee and come back. Learning these days is so simple. Just type what do you want to learn in a search engine like Google. In a second Google will display the result.
Learning anything is like solving your own problem. Like the professionals said brick the big problem into smallest and solve it. This practice had been used for scientist and every person that solved problems.
Before, I suggest you take a look at my previous posts of Python.
Where did I start writing this my python review and you will learn how to install Python in your computer.
The second part of the Python review that you will see the foundation of programming.
Part 3 of my Python review where I start my first code of programming.
Ok, let’s begin learning. The variable, in programming, is a value that can change. Variables can vary according to the condition. Example, the variable with the value of 1 we can change to another number like 3 or 5 and so on. A variable can be protected that you cannot change the value. Remember, in some programming languages, the value of a variable can have different types: 1 is an integer, and ‘Hello, World!’ is a string.
To learn this in an easy way I will define what is a value
A value can have different meanings. In programming, a value is one of the basic things a program works with, like a letter or a number, referred to IDLE of Python 3.7 in your START menu and let’s begin writing some code. Don’t worry it is easiest as you eating doughnut or ice cream.
As you can see the words ‘Hello, World’ is inside of quotation marks and the number without.
I will show what is the type of those. Just typing the function type() and will respond with the type of that value.
The ‘Hello, World!’ printed ‘str’ means a string and the value 15 is printed ‘int’ is an integer.
Go back to variables and learn it simple
According to the Think Python Book. Variables are “one of the most powerful features of a programming language is the ability to manipulate variables. A variable is a name that refers to a value”.
Think Python was written by Allen B. Downey. I have to recommend this book to beginners who want to learn how to programming. The most I like to this book is simplistic and clearness. It helps very much to understand.
Remember, an assignment statement creates new variables and gives them values..
I gave to the variable message the value ‘How are you today?’ remember is a string. The variable n with a value of 17 remember is an integer. The variable pi with a value of its value pi remember is a float.
Let’s print the value of each in the screen. With the function print().
Instead of doing like before typing the string inside of the function print like this print(‘How are you today?’). I just print the value of the variable with the name of it like this print(message). Name of the variable inside of the print parentheses. Same as the variables with numbers values.
Now, to know what the variables type. Just call the function type() with the variables name inside the parentheses.
>>> m = 100,000,000 >>> type(m)
What type is it?