Assignment, Variables, Constants & Sequences
Inputs, Outputs & Type Conversion
IF Statements & Boolean Operators
Nested Selection and Iteration
WHILE, REPEAT-UNTIL Loops
Validation and verification
Validation and authentication routines
High-level & Low-level languages
Assemblers, Compilers & Interpreters
A variable is a location in memory used to store some data (value).
They are given unique names to differentiate between different memory locations. The rules for writing a variable name is same as the rules for writing identifiers in Python.
We don't need to declare a variable before using it. In Python, we simply assign a value to a variable and it will exist. We don't even have to declare the type of the variable. This is handled internally according to the type of value we assign to the variable
We use the assignment operator (=) to assign values to a variable. Any type of value can be assigned to any valid variable.
Click on the run button below to see the output of the python code assigning variables
See if you can improve the output of the code above?
Every value in Python has a datatype. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes.
There are various data types in Python. Some of the important types are listed below.
Integers, floating point numbers and complex numbers falls under Python numbers category. They are defined as int, float and complex class in Python.
We can use the type() function to know which class a variable or a value belongs to.
Click here if you need help ▶
Click on the buttons below to see how variables and data types are used in Java