Variable and Data types in Python

A variable, as the name implies, can be used to store a value that can be change or replaced. You can use a variable to store any value since you can either change the value, by applying it to another value, or retrieve the same value when you call on that variable. Variable in python is like a box (storage place) where you keep your stuff and can come back to it later to either change the stuff or retrieve the stuff when needed. A constant cannot be change and most constant in python are written in capital letter to notify the programmer not to change them, and integers can be used as constant.

In python, do not start your variable with numbers and special characters to avoid syntax error. You can define an object by its Class, and the variable is the object of that class. Variable may not really be declared in python programming. This is because python is dynamically typed noting that the type of variable is checked at run time.

A data type is used to classify inputted data. Since a variable is just a placeholder, keeping the data inputted. Data types are important in programming language to help specify the kind of data inputted by the programmer and processed by the computer. The compiler can easily detect the type of error if the data inputted does not belong to the specific data type. The types of data types include Integer, float, character, string, pointer, Booleans, and void. Integer is either a positive or negative number, but not a decimal number. Float is a decimal number, character can be letters, alphanumeric, letter with symbol (_), string contains characters, pointer is a variable i.e a memory location, Boolean data type is usually represented True or False value, and void returns an empty value.

An example of declaring a variable using python programming language is:

>>> number = 3

>>> print (number)

Output: 3

The variable is ‘number’ and it is of the data type integer.

Leave a Comment

Your email address will not be published. Required fields are marked *