In this tutorial we will learn about data types in python. In python, data types define the kind of data a variable can hold. There are built-in data types like integers, floats, strings, lists, tuples, dictionaries, and sets. Each data type has its own characteristics and functions, allowing you to manipulate and work with different kinds of data effectively.
Numeric Data types
In python we have having a numeric value it can be float, integer, complex number. Now we will discuss each of them.
Integer: In this data will not have any decimal point.
a=12 type(a)
Output:
<class ‘int’>
Float: Numbers with a decimal point.
b=12.0 type(b)
Output:
<class ‘float’>
Complex numbers : In this we have real part and imaginary part.
c=12+4j type(c)
Output:
<class ‘complex’>
String Data type
A sequence of characters enclosed within a single or double quotes.
name='Hi' type(name)
Output:
<class ‘str’>
list Data type
An ordered collection of items, which is mutable(changeable).
my_list=[1,4,6,'banana'] type(my_list)
Output:
<class ‘list’>
Tuple Data type
It is same as list data type but it is immutable(unchangeable).
my_tuple=(1,2,3) type(my_tuple)
Output:
<class ‘tuple’>
Dictionary Data type
A collection of key-value pairs, unordered. It is used to store data values like a map. In this dictionary we have key-value pair dictionary is separated by a colon and key is separated by comma.
my_dict={'name': 'Sri', 'value': 25} type(my_dict)
Output:
<class ‘dict’>
Set Data type
An unordered collection of unique item. It is unordered collection it is mutable and has no duplicate elements.
my_set={1,2,3} type(my_set)
Output:
<class ‘set’>