In this Page, We are Providing Introduction to Python – Object. Students can visit for more Detail and Explanation of Python Handwritten Notes Pdf.
Introduction to Python – Object
Introduction to Python Object
“Object” (also called “name”) is Python’s abstraction for data. All data in a Python program is represented by objects or by relations between objects. Every object has an identity, a type, and a value. An object’s identity never changes once it has been created; it can be thought of it as the object’s address in memory. The id () function returns an integer representing its identity (currently implemented as its address). An object’s type determines the operations that the object supports and also defines the possible values for objects of that type.
An object’s type is also unchangeable and the type () function returns an object’s type. The value of some objects can change. Objects whose value can change are said to be “mutable”; objects whose value is unchangeable once they are created are called “immutable”. In the example below, object a has identity 31082544, type int, and value 5.
>>> a=5 >>> id (a) 31082544 >>> type (a) <type 'int'>
- The Difference Between == and is in Python
- Python Interview Questions on Introduction to Python
- Python Data Persistence – property () Function
Some objects contain references to other objects; these are called “containers”. Examples of containers are tuples, lists, and dictionaries. The value of an immutable container object that contains a reference to a mutable object can change when the latter’s value is changed; however, the container is still considered immutable because the collection of objects it contains cannot be changed. So, immutability is not strictly the same as having an unchangeable value.
An object has an attribute(s), which are referenced using dotted expressions. For example, if an object ABC has an attribute PQ, then it would be referenced as ABC. PQ. In the following example, upper () is an attribute of var object.
>>> var= 'hello' >>> var.upper() 'HELLO'
In the above example, upper () is a function on some object var, and this function is called “method”. More information on “method” is given in chapter 6.