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}