Chereads / PYTHON / Chapter 4 - 1.

Chapter 4 - 1.

1. illustrate the use of method overriding explain with example

2. Illustrate data abstraction with proper example

3. State use of namespace in python

4.what is local and globle variables

5. List built in class attributes

6. What is object give example

7. List reading keyboard input function

1. use of method overriding example

>

-

when you have two methods with the same name that each perform different tasks.

-

the child class has access to the properties and functions of the parent class method while also extending additional functions of its own to the method

class Animal:

def Walk(self):

print('Hello, I am the parent class')

class Dog(Animal):

def Walk(self):

print('Hello, I am the child class')

print('The method Walk here is overridden in the code')

r = Dog()

r.Walk()

r = Animal()

r.Walk()

Output

The method Walk here is overridden in the code

Hello, I am the child class

Hello, I am the parent class

2. Illustrate data abstraction with proper example

>process of hiding the real implementation/carry out of an application from the user and emphasizing/importance only on usage of it.

-

For example, consider you have bought a new electronic gadget. Along with the gadget, you get a user guide, instructing how to use the application, but this user guide has no info regarding the internal working of the gadget.

3. State use of namespace in python

>

1. State the use of namespace in python

-The namespace helps the Python interpreter to understand what exact method or variable is trying to point out in the code.

-A namespace is a system that has a unique name for each and every object in Python

-Python itself maintains a namespace in the form of a Python dictionary

-the role of a namespace is like a surname

-One might not find a single "Alice" in the class there might be multiple "Alice" but when you particularly ask for "Alice Lee" or "Alice Clark"

2. local ๐Ÿ˜‡ & global๐Ÿ˜ˆ variable

-๐Ÿ˜‡A variable declared inside the function is called local function".

-๐Ÿ˜ˆGlobal variables are those which are not defined inside any function and have a global scope

3.list buit-in class attributes in python

โˆ’

1.__dict__

โˆ’ Dictionary containing the class's namespace.

2.__doc__

โˆ’ Class documentation string or none, if undefined.

3.__name__

โˆ’ Class name.

4.__module__

โˆ’ Module name in which the class is defined. This attribute is "__main__" in interactive mode.

5.__bases__

โˆ’ A possibly empty tuple containing the base classes, in the order of their occurrence in the base class list.

6. What is object give example

>

collection of data (variables) and methods (functions) that act on those data. Similarly, a class is a blueprint for that object.

We can think of a class as a sketch (prototype) of a house. It contains all the details about the floors, doors, windows, etc. Based on these descriptions we build the house. House is the object.

7. List reading keyboard input function

>

two inbuilt functions to read the input from the keyboard

input ( prompt )

-The input from the user read as string and can assigned to a variable. After entering the value from the keyboard, we have to press the "Enter" button. Then the input() function reads the value entered by the user

raw_input ( prompt )

scan(),

readline(),

print().