‘’’DATA TYPES COMPARISION ‘’’
Every value in python has a datatype. Since everything is an object in python programming, data types are classes and variables.
There are various data types in python. Some of the important data types are listed below.
Mutable objects — Where we can change the elements after they got created.
for example — set , list, dictionary
immutable objects — we can’t change elements after they got created.
examples — tuple, string, string, frozen set
1. NUMERIC TYPE
Integers, floating point numbers and complex numbers fall under python numbers category . They are defined as int , float , complex classes in python.
We will use the type()
function to know which class a variable or a value belongs to.
#Integer
#float
#Complex number
complex number consists of two parts real and imaginary which is 2 and 7j respectively.
2. DICTIONARY
Dictionary is an unordered collection of key-value pairs. In python, dictionaries are defined within braces { } with each item being a pair in the form of key : value.
{1: ‘a’, 2: ‘b’, 3: ‘c’}
where 1 is key and ‘a’ is value
Allowed key datatypes — int, float, string, complex, Tuple, Boolean.
Allowed value datatypes — all
Duplication of items is not allowed.
Keys will update value if duplicated.
Values can be duplicated.
Adding/Removal/Modifying items are allowed.
Indexing is not allowed, but values can be accessed using keys.
NOTE-; Dictionary is Immutable that means we can not change the items
3. BOOLEAN
Boolean is a data type that has only of two possible values, Which is intended to represent the two truth values either True or false.
These are the few examples of Boolean type -;
4. SET
Set is an unordered collection of unique items. Set is defined by values separated by comma inside curly braces { } . Items in a set are not ordered.
We can perform set operations like union, intersection on two given sets. Sets have unique values and they eliminate duplicates. Since , set are unordered collection, indexing has no meaning. Hence, the slicing operator [ ] does work.
Not all datatypes are allowed.
2 . Indexing, Slicing is not allowed.
3. Duplicates are not allowed.
4. Adding/removal of items is allowed.
5. Cannot replace/modify items
5. SEQUENCE
Strings , List, Tuple fall under Sequence category.
#STRINGS (‘ ’) (“ ”) (“‘ ’’’)
Strings are arrays of bytes representing Unicode characters. Strings in python are surrounded by either single quotation marks, or double quotation marks.