Wednesday 16 September 2020

Unit 1 What is Pointer in Python?

 




What is Pointer in Python?

Variables which serve the special purpose of storing the address of other variables, pointing to the address of the variable of which the address is provided, with obtaining of the value stored at the location being called dereferencing, like a page number in the index of a book that drives the reader to the required content, with performance for repetitive operations like traversing data structures being significantly improved, especially in terms of time and space constraints, supporting effectively the copy and access operations, and are indirectly supported as a concept by Python programming language are termed as pointers in Python.

Syntax of Pointer in Python

>>> variable name = value;

Example – 1

>> a = 2
>>> a
>> 2

Example – 2

>>> b = “Bob”
>>> b
>>> Bob

How to Create Pointers in Python?

Below is an example of creating pointers with isinstance () function to prove that it is an object type. We will see all possible datatypes in Python with isinstance() function, this way you will learn how to declare all datatypes in python as well.

Code:

// assigning an integer value
a = 2
print(a)
// checking if integer is an object or not
print(isinstance(a, object))
// assigning a string value
b = "Bob"
print(b)
// checking if string is an object or not
print(isinstance(b, object))
// assigning a list value
inputList = [1,2,3] print(inputList)
// checking if list is an object or not
print(isinstance(inputList, object))
//assigning a set value
inputSet = {10,20,30}
print(inputSet)
// checking if set is an object or not
print(isinstance(inputSet, object))
// assigning a tuple value
inputTuple = (100, 200, 300)
print(inputTuple)
//checking if tuple object or not
print(isinstance(inputTuple, object))
// assigning a dictionary value
inputDict =   {
"0": 1922,
"1": "BMW",
"2": 100
}
print(inputDict)
//checking if  dictionary is an object or not
print(isinstance(inputDict, object))

No comments:

Post a Comment