The Beginners Guide To Python Variables And Data Types

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.

Python Variables

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

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.

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 :

  1. Numbers
  2. Strings
  3. Lists
  4. Tuples
  5. Dictionary
  6. Boolean

Since this tutorial is getting long, I have elaborated the data types in separate tutorials. Please check them.

 

Leave a Reply

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