In the last article, you have learned about how to run the python programs in Windows and Linux systems. If you haven’t read that article, please read it once. In this article, you will understand the python variables and data types in a better way as I have written it very lucidly.
Simply, variables are the names of the memory locations where our data/values are stored. Even though, variables are very common in every programming language but declaring a variable is never be the same.
Unlike other high-level programming languages like C and Java, We don’t need to declare a variable data type in python. The Python interpreter itself will do it for us. In python, the names of Variables and functions are also called as Identifiers.
One should follow these rules while naming the identifiers in the python.
- You can’t name an identifier which is already a keyword in python. Keywords are some special purpose words which are reserved to do some specific actions. Some of them are True, False, finally, is, return, continue etc.
- you can use letters, digits, and underscores in an identifier’s name. Length of an identifier name doesn’t matter.
- An identifier name must start with letters and even underscores only. But not digits
2greet = "hello" #wrong
greet_2 = "hello" #right
Now, Let’s know how to assign a value to a variable in python. As I said earlier, we don’t need to declare a variable in python. We can simply assign a value to the variable with “=” assignment operator.
Typically, the values of the python variables are in the form of int, float, and string.
- int – numbers like 1,22,4,5, etc
- float – decimal numbers like 2.5, 5.6 etc
- string – “hello world”, “234”, “hello234”
Comments In Python Programming
In every programming language, comments are used mainly for documentation and to make few lines dead in the code. In python, we use ” # ” to comment. The interpreter will ignore the code which has # in starting.
import sys #importing sys module
# print("hello World) - Interpreter will ignore this.
Python Data Types :
Data types are used to differentiate the large set of data into particular kind of data. We have six type of data types in python namely :
Since this tutorial is getting long, I have elaborated the data types in separate tutorials. Please check them.