Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

oops concept in python

1 Object - a variable or a method with attributes
2 Class - a definition of an object's attributes and methods 
3 Polymorphism - having one common name and many forms
4 Encapsulation - hiding attributes or methods as needed
5 Inheritance - makes new object from parent attributes and methods

Some common relations:
- Inheritance makes code reuse possible i.e. create a child class
- Encapsulation - hides the internals of a class to make it 'simple' to use
- Polymorphism - makes it possible to use the 'same method name' while selecting a specific one based on context or arguments
- Concrete - a class with implementation (used for tight coupling(not recommended))
- Abstract - a class with no implementation (used for loose coupling)
- Abstraction - defines a method (category) with no implementation to allow for the needed 'loose coupling'  
- Coupling - determined based on argument being abstract or concrete
- Tight Coupling - argument is a concrete class 
- Loose Coupling - argument is an abstract class   

Analogies:
- Concrete vs Abstract - e.g. 'orange juice' is concrete while 
  'somethingToDrink' is abstract. (in case 'orange juice' gets obsolete, 
    we make sure code always access 'somethingToDrink' instead.
                                   this makes code more readable.)
- Encapsulation - e.g. a car driver usually does not need to know what a
  car mechanic knows i.e. a car driver starts the car and keeps it running. 
  The details of "why" it is running is encapsulated in the car.
- Tight and Loose coupling
    if I say I want 'orange juice' and there is no stock the code runtime "breaks"
    if I say I want 'fruit juice, citrus' there will be more options possible and a chance runtime can do something about it   
 
Comment

oops python

class A:
    def a(self,st):
        return 1
            
    def b(self,s1,s2) :
        d= self.a(7)
        return d    
obj=A()
print(obj.b(1,2))
//prints 1
// so basically every function in a class have self which is object
// like in each of them self is there -- def a(self,st): & def b(self,s1,s2):
// used to other functions of that class and 
//it's used to call other functions & while calling that other function
// we don't write self inside it
// d= self.a(7)
Comment

python oops

Python OOPs (object-oriented programming      stuff)
Object - a unit of code and data in processor memory with defined variables, date, methods
Class - A template of an object that defines variables, date, methods
Method - equivalent of a function, but it is inside a class
Inheritance - A new child class is created from a parent class 
Polymorphism - the same thing implemented in as many ways as needed 
Abstraction - hides unnecessary details
Encapsulation - Wrapping code and data together into a single unit.

https://www.javatpoint.com/python-oops-concepts7
Comment

python oops

IN PYTHON 
unlike javascript don't use . operator to create/assign dic. keys to value
use dic[key] syntax not dic.key(like java script)

NOTE:
in pythyon oops we only use  . operator to access methods and attributes
and to even access using reference variable like head in linkedlist
Comment

PREVIOUS NEXT
Code Example
Python :: Adding new column to existing DataFrame in Pandas 
Python :: how to plot using pyplot 
Python :: draw canvas in python 
Python :: function in function python 
Python :: pyton for 
Python :: for range python 
Python :: how to check if a value is nan in python 
Python :: Tree: Inorder Traversal 
Python :: python libraries 
Python :: optional arguments python 
Python :: program to count the number of occurrences of a elementes in a list python 
Python :: how to create template folder in django 
Python :: how to read frame width of video in cv2 
Python :: how to print even numbers in python 
Python :: run python from c# 
Python :: create a list of the keys in python dictionary 
Python :: IndexError: list assignment index out of range 
Python :: reverse the string in python 
Python :: quiz game in python 
Python :: tkinter bg button 
Python :: python matrix determinant without numpy 
Python :: how to iterate tuple in python 
Python :: axes_style seaborn 
Python :: autopy python not installing 
Python :: how to make a do while in python 
Python :: python frozenset 
Python :: 2d array python initialize 
Python :: TypeError: can only concatenate str (not "method") to str 
Python :: how to make window pygame 
Python :: Math Module radians() Function in python 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =