0% found this document useful (0 votes)
17 views12 pages

4-Python Data Types, Declaring and Using Numeric Data Types - Int, Float, Complex and String-01-03-2023

This document discusses Python numeric data types including integers, floats, complexes, and strings. Integers are whole numbers that can be positive, negative, or zero. Floats represent decimal numbers and can use scientific notation. Complex numbers contain real and imaginary components. Numbers defined with quotes become strings rather than their numeric type. The type() function determines the data type of a variable.

Uploaded by

Ayush Sinha
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)
17 views12 pages

4-Python Data Types, Declaring and Using Numeric Data Types - Int, Float, Complex and String-01-03-2023

This document discusses Python numeric data types including integers, floats, complexes, and strings. Integers are whole numbers that can be positive, negative, or zero. Floats represent decimal numbers and can use scientific notation. Complex numbers contain real and imaginary components. Numbers defined with quotes become strings rather than their numeric type. The type() function determines the data type of a variable.

Uploaded by

Ayush Sinha
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/ 12






Prepared by Dr. Arun Pandian J 59


Prepared by Dr. Arun Pandian J 60
Prepared by Dr. Arun Pandian J 61
Prepared by Dr. Arun Pandian J 62

• mutable objects by changing the element the id() value will not
change , whereas for immutable objects id() value will change.

Prepared by Dr. Arun Pandian J 63


Mutable objects:
list, dict, set, byte array

Immutable objects:
int, float, complex, string, tuple, frozen set
[note: immutable version of set], bytes

Prepared by Dr. Arun Pandian J 64


Declaring and using Numeric data types

•Integer
•Float
•Complex
•String

Prepared by Dr. Arun Pandian J 65


Integer

• Integers are one of the Python data types. An integer is a whole


number, negative, positive or zero.
• In Python, integer variables are defined by assigning a whole number
to a variable. Python's type() function can be used to determine the
data type of a variable.

>>> a = 5
>>> type(a)
<class 'int'>

Prepared by Dr. Arun Pandian J 66


Float
• Floating point numbers or floats are another Python data type.
• Floats are decimals, positive, negative and zero.
• Floats can also be represented by numbers in scientific notation which contain exponents.
• Both a lower case e or an upper case E can be used to define floats in scientific notation.
• In Python, a float can be defined using a decimal point . when a variable is assigned.

>>> c = 6.2
>>> type(c)
<class 'float'>
>>> d = -0.03
>>> type(d)
<class 'float'>
>>> Na = 6.02e23
>>> Na
6.02e+23
>>> type(Na)
<class 'float'>

Prepared by Dr. Arun Pandian J 67


Complex
• Another useful numeric data type for problem solvers is the complex
number data type.
• A complex number is defined in Python using a real component + an
imaginary component j.
• The letter j must be used to denote the imaginary component.
• Using the letter i to define a complex number returns an error in
Python.

>>> comp = 4 + 2j
>>> type(comp)
<class 'complex'>

Prepared by Dr. Arun Pandian J 68


String

• Numbers and decimals can be defined as strings too. If a decimal


number is defined using quotes ' ', the number is saved as a string
rather than as a float.
• Integers defined using quotes become strings as well.

>>> num = '5.2'


>>> type(num)
<class 'str'>

>>> num = '2'


>>> type(num)
<class 'str'>

Prepared by Dr. Arun Pandian J 69


Thank You

Prepared by Dr. Arun Pandian J 70

You might also like