Data types are the classification of data items. Data types represents a kind of value which determines what can be done to that data.
There are different types of data types in Python. Some built-in Python data types are:
- Numeric data types
- Integer
- Float
- Complex Number
- Sequence types
- String
- List
- Tuple
- Boolean type
- Dictionary
- Set
Numeric data type:
In numeric data type we can have numeric values like integers, float, or can be complex number.
• Integers (int) – it is represented by int class. It can be positive or can be negative whole number. It should not be in fraction or decimal.
# integer variable.
a = 10
print(type(a))
• Float (float) – it is represented by float class. It contains real number with floating points. Decimal point is the specificity.
# float variable.
b = 10.5
print(type(b))
• Complex numbers (complex) – It is represented by complex class. It is denoted by (real part) + (imaginary part)
# complex variable.
c = 1 + 5j
print(type(c))
Sequence Type:
Sequence data type is the ordered collection of similar or different data types. It gives the permission to store multiple values in an organized and efficient manner. These are the following types of sequence data type
• String
• List
• Tuple
1) String
Strings are arrays of bytes denoted by Unicode characters. It can be collection of one or more characters and can be put in a single quote, double-quote or triple quote. No character data type exists in Python, a character is a string of length one. It is represented by str class.
#string datatype
great = "Hello World"
print(great)
print(type(great))
2) List
Lists is like arrays which is declared in other languages that is an ordered collection of data. It is very flexible as the items in a list does not requires of the same type.
#List Example
fruits = ["apple", "banana", "cherry"]
print(fruits)
print(type(fruits))
3) Tuple
Tuple is also an ordered collection of Python objects like list. The only difference between tuple and list is that tuples are immutable. It means tuples cannot be modified after once it is created. It is represented by tuple class.
#Tuple Example
fruits = ("apple", "banana", "cherry")
print(fruits)
print(type(fruits))
Boolean Type:
True or False these are two built-in values used as data type. It is denoted by the class bool.
statement = True
print(statement)
print(type(statement))
Dictionary :
Dictionary is an unordered collection of data values. Dictionary holds key:value pair. Each key-value pair in a Dictionary should be separated by a colon :, whereas each key is separated by a ‘comma’.
emp = {"name" : "Shiva", "age" : 24}
print(emp)
print(type(emp))
Set :
Sets are used to store multiple items in a single variable. A set is a collection which is unordered, unchangeable*, and unindexed.
fruits = {"apple", "banana", "cherry"}
print(fruits)
print(type(fruits))
- Data types represents a kind of value which determines what can be done to that data.