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 :: python variable scope 
Python :: multiplication of two or more numbers in python 
Python :: pil format multiline text 
Python :: <IPython.core.display.HTML object 
Python :: how to access items in a list 
Python :: how to remove role discord bot python 
Python :: python sort an array 
Python :: csv read python 
Python :: seaborn boxplot legend color 
Python :: how to convert a datatype to another 
Python :: color plt 
Python :: Disctionary to Array 
Python :: python tuple and dictionary 
Python :: argparse accept only few options 
Python :: statsmodels 
Python :: read list stored as a string with pandas read csv 
Python :: check if string match regex python 
Python :: python update header row 
Python :: python selenium print element 
Python :: python string to operator 
Python :: python list to dataframe as row 
Python :: dataframe multiindex 
Python :: python isin 
Python :: Normalize columns in pandas dataframe2 
Python :: tic-tac toe in pygame 
Python :: how to configure a button in python tkinter 
Python :: python dictoinary add value 
Python :: get discord guild members discord.py 
Python :: pandas aggregate dataframe 
Python :: python sort by highest number 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =