Data Types
Data Types
Dr.V.V.Sumanth Kumar
Principal Scientist
ICAR- NAARM
Hyderabad
Data Types
• In python programming, every value has its own python data types
Classification
Sequence
Numeric Dictionary Set Boolean
Type
Integers string
Float list
Complex
numbers tuples
Classification..
• Mutable objects can change its state or contents and immutable objects cannot.
Int
List Dictionary
Float
Complex
Tuple
String
set
Numeric Data Types
• data with numeric value is known as Numeric data type
• value can be any number data type such as integers, floating number or complex numbers
• can read as int, float and complex class in python.
• floating numbers defined as decimal point, the value can be defined as float class
Float • Eg:10.5,7.2 etc.
• program
Integers
• Python program: a=9 print(a,type(a))
• Output: 9 <class ‘int’>
Float
• Python program: a=90.2 print(a,type(a))
• Output: 90.2 <class ‘float’>
Complex
• Python program: a=4+4j print(a,type(a))
• Output:(4+4j) <class ‘complex’>
Sequence Data types
• Ordered collection of different data types, like string, list and tuples.
String:
• defines the characters
• collection of one or more characters in single quotes or double quotes
• multi line strings can be denoted by triple quotes ‘’’ or”””
output:
this is string program
hii
welcome to python subject
this is multi line string program
<class 'str'>
Lists
Lists:
• ordered sequences of items, more frequently used in the python programming and convenient to use.
• mutable ,changes can be done .
• can be written in the [ ]
• eg:a=[1,3.1,’s’]
Program:
Output:[24,’sweet’ 13]
• mutable that indicates changes like updating, deleting other changes can be done, consider the above
example.
• Here A[1]=HII, values start from 0,1,2 so in first position that” sweet” being updated
Program:
Output: [24,’hii’13]
Tuple
• Same as the list, with the ordered sequences of the items, can written in the parentheses(), it is
separated by commas.
• one items cannot be shown or taken, it would be considered as the int or string,
• contain more than 1 or 2 values in it.
• immutable, fast and flexible compared to the list.
• Eg:a=(88,36,’hi’)
Program:
Output:('hii', 23, 28, 29)
('hii', 23, 28, 29) <class 'tuple'>
Tuple is immutable
eg: program
A=(hii,23,28,29)
A[1]=99
Print(A)
Output is shown in picture, not supported.
Dictionary
• unordered collection of key –value pairs eg: program
d={
• defined by with in the braces{} 'course_name' : 'python',
• displayed key value format 'course_type': 'programming',
'course_duration' : '2 months'
}
print(d)
Output:
{'course_name': 'python', 'course_type': 'programming',
'course_duration': '2 months'}
• d={
• defines the key –value 'course_name' : 'python',
• giving key the value can be defined 'course_type': 'programming',
'course_duration' : '2 months'
• mutable changes can be done . }
print(d['course_name'])
print(d)
• Output:python
• {'course_name': 'python', 'course_type': 'programming', 'course_duration': '2
months'}
Set and Boolean
Set:
• unordered collection of elements, every element in set must be unique no duplications are done
• immutable no changes can be done , represented in{}.
• duplication number is removed automatically in the program
Eg:program
s={10,20,20,40,40}
Print(s)
Output:{10,20,40}
Boolean:
• represented by two outcomes “TRUE and FALSE”
• any non zero is true and zero value is true.
Program:
Print(bool(4))
Output :true
Print(bool(0))
Output: false.
Differences
LIST TUPLE SET