Datatypes in Python.


Datatypes in Python.

In this post we will talk about Datatypes in Python. Let's start..!

First of all we should know different types of datatypes. Here I have listed some basic datatypes with it's description.

In Python you don't need to specify a datatype of any variable that will be done by Python itself. If you want to specify a datatype of any variable then you can specify that also. 

If you want know datatype of any variable then you can use a special inbuilt function i.e. type( variable ) . Just follow this post you will learn all about datatypes.


1} None

If you defined a variable but you still not assigned any value to it. It means that variable is of None datatype. Simply variables with  None datatype does not any value. or The variable without any value is of None datatype.

2] Numeric 

Numeric datatype have their 4 sub-datatypes that are as follows :

    1] int 

    This datatype is mostly used by programmers. This datatype stores a integer value. for ex. 1, -2 , 99, -100 etc.




2] float 

    This datatype almost same as int only difference is that this datatypes stores integer floating point numbers. Simply the numbers having decimal point will be store in float datatype. for ex. 11.4, 58.5, -45.09, -3.0 etc.




3] complex 

    This datatypes stores a complex numbers. In mathematics surely you have learned about complex numbers. for ex. 6 + 5j ( in mathematics we use i but instead of i we are using j  here ) .




4] bool 

    This datatype can stores only two values that is True or False.  This boolean datatype used for checking conditions normally.  




3] String

This datatype can stores all characters. We can store a single character or a multiple character or string ( group of character ). Your character or string should be in double cote. for ex. "Jack", "y", etc.




4] List 

List datatype stores any value. It means list can store integer, float, string, boolean etc. To create list you should give a '[ ]' and in square bracket you can store your values. To separate values in list we use ',' there. Simply you can stores any datatype value in list and that value should separated by a comma ( , ). for ex. [90, 99.9, True, "jack" ].List can stores duplicate value also. And important point is we can change values in list or add another value to list or remove existing value from list. You can also store a list inside a list. but how that we will see in some next posts. we can access values using indexing in list. this features makes list more powerful.




5] Set

This datatype is also same as list datatype. It can also stores values of different datatypes. But we can't access value in set using indexing. Also we can't store duplicate values in set. But all datatypes have their special properties. Every datatype have their special use. To use set we have to use '{ }' . for ex. { 27, "hello", 273}




6] Dictionary 

This datatype is something different from another datatypes. Because in this datatypes we store values in 'key : value' pair. To access values of dictionary we have to specify their key and using key we can access values in dictionary. Dictionary can stores duplicate values but we can't specify duplicate keys, Every key should be unique. Here also we can store values of different datatypes. And to use dictionary we have to use '{ }' and values should have their keys. '{ key : value }'. Your key should be in double cote "" . for example { "value1": 30, "value2" : 50, "value3" : "Jack" }.  




7] Tuple

This datatype is used to store multiple values in a single variable. Means once you store values in tuple you cant change it. In tuple we can store duplicate values. Tuple has indexing also. We can stores values of different datatypes. To use tuple we have to used '( )' for ex. ( 923, "jack", 7, True).




This is all about Datatypes in python. Try something your own.

What is operator ? and How to use operator ? that we will see in next post.


If you have any doubts in this post then please ask me in comment section below. I will try to solve it.


If you like these post and you have learned something from this then share this post with your friends and family.

Keep learning always.....!!! 😇😇😇




Previous Post  Next Post