A data type is a numbers,words,measurements,observations or observations that a variable or object can hold in computer programming.
Data Any Variable Declared in python programming has a data type according their type of observed values. Every data type in Python language needs storage or amount of memory. And specific operation can be performed on it.
Once a value assigned to a variable It can store any kind of data like integer, character, floating, double, boolean, complex, string,list,tupple etc. The data type is a group of data with values having fixed values, meaning as well as its characteristics.
Python is dynamically typed language hence do not need to declare data type is automatically detects data type of a variable depending upon value assigned .
e.g . a=25
here a is assigned value 25 and its data type is <class,'int' >.
Data Type: “ Data Type in Python programming specifies what kind of values does variable store or hold and the kind of operation performs on the values”.
Data Type describes chaacteristics of variable.
Python is object oriented, hence everything in python is object .Datatypes in python are classes and variables are instances of the class.
Python provides type() function to check the data type of a variable.
Data Types in Python: :
Python has following built in data types .
1. Numberic.
2. Sequence.
3. Dictionary.
4. Boolean.
5. Set.
1. Numeric Data type:
Numeric data types are the numbers stored in python variable. Numeric or number data types in python are grouped on their numeric values.
The exact Type of Numeric or Number Data types in python are
a. Integer:
In Python Integers are hole number either zero, positive or negative numbers without fractional part in it , having unlimited precision.
e.g >>>a=6
>>>a=456577
>>>a=6700000000000000000000000000000000000000000000000
b.Float:
Float Data type in Python are numbers that can be a positive and negative real numbers with a fractional part denoted by the decimal symbol . or the scientific notation E or e,
e.g. 1234.56, 3.142, -1.55, 0.23.
>>> g=9.8
>>> g
9.8
>>> type(g)
<class 'float'>
c.Complex:
Complex data type is one of the inbuilt data type in python. Complex data type have two values. The value is the real part of a number and second one is the imaginary part of the complex number.
In complex number Imaginary part is denoted by i
And real part is denoted by j.
e.g 3i+4j.
>>>c=1+2j
>>>type(j)
<class ‘complex’>
# e.g Python script To Demonstrate Numeric /Numbber Data Type in Python
a = 6 #int
print(a)
print(type(a))
g = 9.8 #float
print(g)
print(type(g))
c = 1+2j #complex
print(c)
print(type(c))
output:
6
<class,’int’>
9.8
<class,’float’>
1+2j
<class,’complex’>
2. Sequence Data type:
Sequence data type store is a container that store different data values in organised or sequential ordered form.
Sequence Data Types in Python has Three sub types
i. String:
A string is defined as a collection of one or more characters.
It iscan be put in single quotes or double quotes or triple quotes i.e (' ') , (" ") or (' ' ' ' ' ') .
for eg: s="www.python.org" .
e.g
s=”Wellcome”
print(s)
print(type(s))
output:
welcome
<class,’str’>.
ii. List:
List is a group or collection of heterogeneous data type. It hold any kind of data.
L=[1,”one’,2.5]
Print(L)
Print(type(L))
[1,”one’,2.5]
<class,’list’ >.
iii. Tuple :
Tuple is a ordered collection of a any data values which cannot be changed means Tuples are immutable. once a tuple is created whose items cannot be modified.
Tuples created with ().
T=(1,2,”three”)
print(T)
print(type(T))
Output:
(1,2,”three”)
<class,’tuple’ >
3.Dictionary:
Dictionary in python is an ordered collection of data items. Items in dictionary is changeable and cannot allow duplicates data items. It has key:value pair which is separated by a colon :, and all keys are separated by a ‘,’.
eg :
mydict={'age':25, 'b':2, 'three':3}
y = {"name" : "python", "age" : 40} #dict
print(y)
print(type(mydict))
{'name': 'python', 'age': 40}
< class 'dict' >
4.Boolean:
Booleans data type is one of the inbuilt data type in python used to represent one of two values: True or False.
a = True #bool
print(a)
print(type(a))
True
<class 'bool'>
5.Set :
Set is an unordered ,unique collection of data types that are mutable (change)and has distinct elements.
eg: s={1,2,3,4,5}
y = {"Python", "C", "CPP"} #set
print(y)
print(type(y))
output
{'Python', 'C', 'CPP'}
<class 'set'>
Next topic Operators and Expressions