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