ROLE OF DATA TYPES IN PYTHON
Datatypes of python:-
— — — — — — — — — — — — — — —
In the current scenario Python is considered as a simple , versatile programming language due to its simple coding structure, ease to understand and all-round use proposal. Weather we talk about web development, data science, machine learning , automating a task, python’s data types play a crucial role in it. Data types in python makes it best programming language. We may say data type in python is the heart of python language. In python there are 14 types of data types divided into 6 categories:-
1: Fundamental Category
— — — — — — — — — — — — — — — — — — —
1: integer
2: float
3: bool
4: complex
2: Sequential Category:-
— — — — — — — — — — — — — — — —
5: str
6: range
7: bytes
8: byte array
3: List Category:-
— — — — — — — — — — —
9: List
10: tuple
4: Set Category:-
— — — — — — — — — — —
11: Set
12: frozen set
5: Dict Category:-
— — — — — — — — — — — —
13: Dictionary
6: None Category:-
— — — — — — — — — — — — —
14: None
1:integer-
— — — — — —
-> The Integer data type is mentioned as int which stores only whole number.
-> Int data type mainly stores 4 types of number system:-
* Decimal number system
* Binary number system
* Octal number system
* Hexadecimal number system
-> we can convert other data type into integer data type using int().
2:float:-
— — — — —
-> It stores decimal values.
-> We can convert other datatypes into float data type using float().
-> We can store floating point values by using scientific notation.
-> The general format of scientific notation is ‘Mantissa E Exponent’
Mantissa E Exponent = Mantissa * 10 to power Exponent
Get Omprakasdash’s stories in your inbox
Join Medium for free to get updates from this writer.
Ex:- 3 e 2 = 3* 10**2 = 3*10*10=300
3:bool:-
— — — — —
-> It represents the value in true or False.
-> If the condition satisfied, it returns True otherwise Returns False.
-> If we convert the bool data type into int data type, then the value of True will be 1 and the value of False will be 0. So that we can perform mathematical operation in True and False.
-> We can convert other data types into bool by using bool().
-> When we convert other data type into bool, if the object contains any value then it returns True otherwise it returns False.
4:Complex:-
— — — — — — — —
-> It stores the complex value or imaginary value.
-> General structure:- a+bj or a-bj
-> a is the real part , b is the imaginary part and j represents sqrt(-1).
-> Internally both real part and imaginary part are treated as float value.
Ex:- 2+5j, 4–8j, 4+j etc.
5:str:-
— — — —
-> In str, we store all data types within two single quotations or double quotations or two triple single quotations or two triple double quotations.
-> We can store multi line data within str.
-> When we store all these values, it consider each element as single like we store India in str, it will consider it as I,n,d,i,a. So its length will be 5.
-> We can perform indexing and slicing on str object.
-> It is immutable means when we add or remove element from str data type, the changes stored in the same memory address.
6:bytes:-
— — — — — —
-> It stores all data with encrypted format. So that none can access the data.
-> We can say bytes data type is responsible to store our data securely.
-> It has no notation, it is dependent on other data type. Means we can only convert other data types into bytes data type.
Syntax:- bytes(obj)
-> We can store only data between 0 to 255 value. Value greater than 255 can’t be coverted to bytes.
-> It follows insertion order. Means it gives data according we give input.
-> We can perform indexing and slicing in bytes data type.
-> We can’t modify in bytes object. So it is immutable.
7:byte array:-
— — — — — — — — —
-> Like byte data type it also store our data with encrypted format.
-> It store data between 0 to 255 range.
-> The properties of bytes and byte array are same. But the main difference between bytes and byte array is unlike bytes we can modify the byte array object. So we can say byte array is mutable.
-> We can convert any data types into byte array by using byte array(obj).
8:range:-
— — — — — —
-> Range indicates to store sequence of numerical value within a range.
-> it has a start point and a end point. The value will starts from the start point and ends before the end point with a fix interval.
->The data may be in forward direction or in backward direction.
-> We can perform both indexing and slicing in range value.
-> We can’t assign data in range object. So it is immutable.
-> We can’t execute range data type without for loop.
9:list:-
— — — —
-> It stores all data types within a single object.
-> In list, the elements are stored within square bracket, separated by comma.
-> we can update list object with same memory address. So we can say it is mutable object.
-> It supports both indexing and slicing.
-> List maintains insertion order.
-> We can perform both sort and sorted function. The data type of output will be list.
-> When we perform sorted function on any immutable object, the data type of output will be list.
10:tuple:-
— — — — — —
-> Tuple is the data type which stores all data types within a single object like list.
-> But the main difference is unlike list, it is immutable. Means we can’t update tuple object.
-> We can’t update tuple directly, but we can update tuple by converting it to list ,then update list amd again convert it to tuple.
-> As it is immutable object, we can perform sorted function on it. But can’t perform sort function on it.
-> After using sorted function, The data type of output will be list.
-> In tuple, the data are stored within parenthesis separated by comma.
-> We can keep duplicate item in tuple.
11:set:-
— — — — —
-> set data type stores all data types within a single object. But it does not allow duplicate item.
-> In set, the items are stored with curly brackets separated by comma.
-> It does not maintain insertion order. Means the sequence of user data and the set data are not same. So we can’t perform indexing and slicing on set object.
-> It does not allow duplicate items.
-> set performs both mutable and immutable property.
-> set allows to add or remove items. So it is called mutable. set does not item assignment. So it is called immutable.
-> Although we can’t perform indexing and slicing on set object. But internally set arrange the elements in index format which can be expressed by enumerate() function.
12:frozen set:-
— — — — — — — — — —
-> Like set, frozen set is also responsible to store unique elements of similar or dissimilar data types.
-> But the main difference is unlike set, it is immutable.
13:dict:-
— — — — — —
-> dict data type store data with key and value pair.
-> The key and value are separated by colon and each pair is separated by comma within curly brackets.
-> Like set, dict is also mutable and immutable.
-> If we consider key and value separately, the key will be immutable but the value will be mutable.
-> The key acts as the index of value. But the object uses the index to store key and value pair which is exprssd by using enumerate() function.
-> The keys are unique but the values can be duplicate.
-> When we entered wrong key, system gives keyerror as output.
-> We can’t perform indexing and slicing on dict object.
-> dict object maintain insertion order.
14:None:-
— — — — — —
-> It is a key word and also treated as data type when an object don’t have any value.
-> The bool value of none type is 0.
-> we can’t assign the value. It is a result, when an object don’t have any value.




