ITEP 206 Lesson 3
ITEP 206 Lesson 3
INTEGRATIVE PROGRAMMING
TECHNOLOGIES 1
LESSON 3
Different Types of Objects
in Python
In Python, the term “object” is
quite the catch-all; including
numbers, strings of characters,
lists, functions - a Python object
is essentially anything that you
can assign to a variable.
Different Types of Object in Python
• File Method
• Set Method
• Tuple Method
• Dictionary Method
• List Method
Number Types
x-y
x // y
x*y
x modulo y
The remainder of x/y for positive x,y
x ** y
-x
A negated number
Abs(x)
x != y
x>y
x<y
x <= y
In effect, this means that a float can only be represented with a numerical
precision of approximately 16 decimal places, when that number is written
in scientific notation. The computer will not be able to reliably represent a
number’s digits beyond those accounted for by the allotted 8 bytes. For
instance, the following Python integer is defined with 100 digits, but when
this number is converted to a float, it only retains 15 decimal places in
scientific notation:
Understanding Numerical Precision
Understanding Numerical Precision
Python has a
read() Returns the file content
readable() Returns whether the file stream can be
read or not
set of methods
readline() Returns one line from the file
readlines() Returns a list of lines from the file
truncate()
Returns the current file position
Set Method in Python difference_update() Removes the items in this set that are also
included in another, specified set
discard() Remove the specified item
intersection() Returns a set, that is the intersection of two
or more sets
isdisjoint()
Removes the items in this set that are not
present in other, specified set(s)
Returns whether two sets have a intersection
pop()
Returns whether this set contains another
set or not
Removes an element from the set
We can add and remove elements form the set with the
help of the below functions –
Method Description
count() Returns the number of times a specified value
occurs in a tuple
index() Searches the tuple for a specified value and returns
the position of where it was found
Tuple Method in Python
Syntax:
tuple.count(element)
Tuple Method in Python Example
Tuple Method in Python Example
Index() Method
The Index() method returns the first occurrence of the given
element from the tuple.
Syntax:
tuple.index(element, start, end)
Parameters:
•element: The element to be searched.
•start (Optional): The starting index from where the searching is started
•end (Optional): The ending index till where the searching is done
Tuple Method in Python Example
Python has a
value pair
set of built-in
keys
As opposed to the pop() method which gets rid of a particular key-value pair
based on a given key, popitem() takes out and gives back a pair without
requiring a key to be specified.
Dictionary PopItem() Method
In Python, the popitem() method is a dictionary function that eliminates and
returns a random (key, value) pair from the dictionary.
As opposed to the pop() method which gets rid of a particular key-value pair
based on a given key, popitem() takes out and gives back a pair without
requiring a key to be specified.
Method Description
Python has a
extend() Add the elements of a list (or any
iterable), to the end of the current list
set of built-in
index() Returns the index of the first element
with the specified value
methods that
insert() Adds an element at the specified
position
list.
remove() Removes the first item with the
specified value
Note: The position mentioned should be within the range of List, as in this
case between 0 and 4, else wise would throw IndexError.
List Extend() Method