Programming Logic : Variables

 

Hello there ,

We are getting deeper and deeper into Code and we are covering Variables.

They are also a Corner stone to Programming.

 A variable is a named value used to operate certain operations in a program.


To explain this better , I am going to use a box to illustrate a variable. 


When you create a variable , You symbolize an empty box.

When you place something in the box , You are giving it a value .

And so that you don't get confused , You slap a sticker that explains what the box is for.

That's what variables do , They hold values and also have names so you can identify them.


More information on Variables

Read this to learn more about Variables

How do we use variables ?

Let's say , We are a creating a Greeting Program.

A simple program that Greets the user after he inputs his Name.


We would create a variable to store that specific name and Greet them.

Visual example of the Greeting program :


There are lots of examples out there that you can look out for and I encourage you to do more research on them.

All Programs use Variables to store values and use them some in the other necessary parts of the program.

What Variables look like in code ?


Just like different items can be stored in only certain containers so are variables.





We shall cover the common different types of variables.
The 5 common types are :

1. Strings 

 A string is traditionally a sequence of characters.

Strings are just a bunch of characters.

"Tim"-- This is a string

"123"-- This is a string also

Any value in "" is a string.


2. Integers

This is a data type used to represent real numbers that do not have fractional values.

123 -- This is an integer

0001 -- This is an integer

0000 -- This is an Integer


Any numerical Value that is a whole number is an integer.


3. Floats

This is a data type used to represent decimal numbers.

1.560 --- This is a Float

3.000 ---This is a Float

1.000 ---This is a Float

Any numerical value with decimals is a float 


4.Booleans

A Boolean data type has one of two possible values (usually denoted true and false), intended to represent the two truth values of logic.

This is used to create two-way Logic.

When this fails(false) or passes(true) , do this....


5. Arrays

An array is a variable that can store multiple values

There are two kinds of arrays besides it

-List

-Dictionary

A dictionary stores values in pairs 

{key:value}

e.g. {name:"Timothy"}


More information on Arrays

Extra information on Arrays


This is pretty much what you needed to know about Variables.

Continue your Hunt for knowledge and You will find all the answers you need.

Have a Good Day !

Comments

Popular posts from this blog

Programming Logic : Basic Operators

What is Young Coders ?

Let's Begin Coding : Choosing a Code editor