Week3 Programming Fundamentals Lecture 7
Week3 Programming Fundamentals Lecture 7
WEEK 03 – PYTHON DATA TYPES, CLASSES AND OBJECTS & VALID VALUES FOR NUMBERS
Course Instructor :
Engr.Asma Khan
Assistant Professor,SE dept
CLASSES AND OBJECTS
So far seen how to use several types of values that Python supports:
int, float, bool, str, list, and tuple.
At this point, we step back for a moment to understand more
formally what we mean by a type, and by operators and methods
supported by the type.
In Python, every value, whether a simple integer value (such as 3)
or a more complex value (such as the string 'Hello, World!' or the list
['hello', 4, 5]) is stored in memory as an object.
It is useful to think of an object as a container for the value that sits
inside your computer’s memory. 10/22/2018 2
An object’s type indicates what kind of values the object can hold and what kind
of operations can be performed on the object. The types we have seen so far
include the integer (int), floating point (float), Boolean (bool), string (str), and list
(list) types. 10/22/2018 3
TYPE()
10/22/2018 4
CONCEPT OF CLASS
10/22/2018 6
RELATIONS BETWEEN OBJECTS
instantiation
instantiation
10/22/2018 9
ANIMAL CLASS AND ANIMAL OBJECTS
10/22/2018 11
VALID VALUES FOR NUMBER TYPES
Every object has a value that must be legal for the object’s type.
For example, an integer object can have value 3 but not 3:0 or 'three'.
The integer values can be arbitrarily large.
For example, we can create an integer object whose value is 21024:
x = 2**1024
print(x)
179769313486231590772930519078902473361797697894230657273430081157732675805500963132
708477322407536021120113879871393357658789768814416622492847430639474124377767893424
865485276302219601246094119453082952085005768838150682342462881473913110540827237163
350510684586298239947245938479716304835356329624224137216
Actually, there is a limit to how large the value stored in an integer object can be:
The value is limited by the available computer memory.
COPY RIGHT - ASST. PROF. SYED FAISAL ALI 10/22/2018 12
PYTHON FLOATING POINT - FLOAT TYPE
The Python floating point (float) type is used to represent real numbers as fractions with
finite decimal representations:
pi = 3.141592653589793
2.0**30
1073741824.0
10/22/2018 13
NUMBER TYPE OPERATIONS
The order in which operators are evaluated is defined either explicitly using parentheses or
implicitly using either the operator precedence rules or the left-to-right evaluation rule if
the operators have the same precedence.
The operator precedence rules in Python follow
10/22/2018 16
ASSIGNMENT # 2
TO BE SUBMITTED BY SOLVING IT ON JUPYTER NOTEBOOK & EMAIL IT TO ME.
10/16/2018 17
PRACTICE PROBLEM 2.8