0% found this document useful (0 votes)
159 views13 pages

Data Types

The document discusses different Python data types including numeric, sequence, and other data types. Numeric data types store numbers and include integers, floats, and complex numbers. Sequence data types store ordered collections like strings, lists, and tuples. Other data types include dictionaries, sets, and booleans.

Uploaded by

ragjni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
159 views13 pages

Data Types

The document discusses different Python data types including numeric, sequence, and other data types. Numeric data types store numbers and include integers, floats, and complex numbers. Sequence data types store ordered collections like strings, lists, and tuples. Other data types include dictionaries, sets, and booleans.

Uploaded by

ragjni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

DATA TYPES

Dr.V.V.Sumanth Kumar
Principal Scientist
ICAR- NAARM
Hyderabad
Data Types

• Humans can understand 1,8,2,3(numbers) and alphabets unlike the

computers, defines or classifies the objects ,variables.

• Categorization of different data items, represents type and indicates

what operations are to performed on specific data .

• 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.

Mutable Data Types Immutable Data Types

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.

• numbers including positive numbers ,Negative numbers along with


Integers zero e.g.:-3,-2,-1,0,1,2,3.

• floating numbers defined as decimal point, the value can be defined as float class
Float • Eg:10.5,7.2 etc.

complex numbers • combination of real part with imaginary part of


j((real)+imaginary), defined by the complex class eg:5+4j,7-2k
Numeric Data Types

• 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

Allow duplicate members Allow duplicate members No duplicate members

Mutable Immutable Immutable

Ordered Ordered Unordered

Square bracket[] Round brackets() Curly brackets{}

You might also like