Basic Data Types in Python - Numbers

Usually every programmer will start with "Hello World!", but for a change lets start with numbers. I personally believe that numbers play vital role than alphabets.

Numbers
For someone who worked on other programming languages, it will be surprise and shock, since python doesn't have a concept called Variable Declaration.

For new beginners, Variable declaration is a technical way of saying the data type for a variable. Let's go with an example.

In Python 2.x,
In Python 3.x,
If you look at both the examples, there is a very minor change. Let's not worry about it now. If you see the variable 'x', we didn't define what kind of value it is going to hold.

We assigned the value of x to 1, we are printing it, and we are also printing the (data) type of x. In the last line we are printing both the type and value of x. The output will be like this:

Output of Numbers
If you look at the output, python understood that the variable 'x' is of type 'int', even though we didn't declare the variable with the data type 'int'. There is no semicolon at the end of the lines (some language tend to have that semicolon at the end of each line).

Another observation from 2.x and 3.x is the open and close brackets. Python 3 has more explicit way of passing the variables, where as Python 2 doesn't have this. This is one among the different between 2 and 3. Here after all my codes will be Python 3, as I mentioned earlier in the post.


You may also like

No comments: