Numeric Data types in Python

jyostnabodapati 1,485 views 15 slides Nov 27, 2020
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

Describes various numeric data types supported by Python like int, float and complex


Slide Content

Numeric Data Types
by
JyostnaDevi Bodapati

Python Programming Specialization
Python Programming –Data Structures
Numeric Data Types
▪Numeric data types represent numeric data such as integers, floating point
or complexnumbers
▪Objects that store numerical type of data come under this category
Numeric
int float complex

Python Programming Specialization
Python Programming –Data Structures
Data Type: int

Python Programming Specialization
Python Programming –Data Structures
Numeric Data Type: int
▪Integersare represented by intclass
▪Integers are the whole numbers without any fractional part
▪Can be positive or negative numbers
▪In Python, Integers can be of any length
▪It’s length is restricted to the system memory

Python Programming Specialization
Python Programming –Data Structures
Numeric Data Type: int
▪Examples:
>>> a = 10
>>> b = 100
>>> c = 11111
>>> d = 3333
>>> e = 234257843112578886

Python Programming Specialization
Python Programming –Data Structures
Integers with other bases

Python Programming Specialization
Python Programming –Data Structures
<class int>: Binary data
▪Binary: Integers with base 2
▪Binary digits followed by 0bor 0Bare treated as binary in
python
>>> a = 0b101 #binary
>>> b = 0B100 #binary
Note: a is 5 and b is 4

Python Programming Specialization
Python Programming –Data Structures
<class int>: Octal data
▪Octal: Integers with base 8
▪Integers (0-7)followed by 0oor 0Oare treated as octal in
python
>>> c = 0o231 #octal
>>> d = 0O347 #octal
Note: C is 153 and d is 231

Python Programming Specialization
Python Programming –Data Structures
<class int>: Hexa-decimal
▪Hexa-decimal: Integers with base 16
▪Integers (0-9, A, B, C, D, E, F) followed by 0xor 0Xare treated as
octal in python
>>> e = 0x23 #hexa
>>> f = 0X3A # hexa
Note: e is 35 and f is 58

Python Programming Specialization
Python Programming –Data Structures
Data Type: float

Python Programming Specialization
Python Programming –Data Structures
Numeric Data Type: float
▪Real numbers are treated as float class
▪Contains both integer and fractional part
▪Can be positive or negative numbers
▪Python floating precision numbers are accurate upto15 decimal places
▪Eitherfloating point representation orscientific representation is valid in
python

Python Programming Specialization
Python Programming –Data Structures
Numeric Data Type: float
▪Examples:
>>> a = 2.3
>>> b = 100.0
>>> c = 0.5e+7
>>> d = 0.00e-4
>>> x = 0.30000000000000004

Python Programming Specialization
Python Programming –Data Structures
Complex Numbers

Python Programming Specialization
Python Programming –Data Structures
Numeric DataType: complex
Numerals with real and imaginary parts are treated as complex class
General Form: (real part) + (imaginary part)j
Ex: -5 + 3j