Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python private

def _private(self):
 # this class function is now private
Comment

python private method

# Python program to 
# demonstrate private methods
  
# Creating a Base class 
class Base: 
  
    # Declaring public method
    def fun(self):
        print("Public method")
  
    # Declaring private method
    def __fun(self):
        print("Private method")
  
# Creating a derived class 
class Derived(Base): 
    def __init__(self): 
          
        # Calling constructor of 
        # Base class 
        Base.__init__(self) 
          
    def call_public(self):
          
        # Calling public method of base class
        print("
Inside derived class")
        self.fun()
          
    def call_private(self):
          
        # Calling private method of base class
        self.__fun()
  
# Driver code 
obj1 = Base()
  
# Calling public method
obj1.fun()
  
obj2 = Derived()
obj2.call_public()
  
# Uncommenting obj1.__fun() will 
# raise an AttributeError 
  
# Uncommenting obj2.call_private() 
# will also raise an AttributeError
Comment

PREVIOUS NEXT
Code Example
Python :: random picker python 
Python :: how to remove spaces in string in python 
Python :: pyspark group by and average in dataframes 
Python :: python pathlib create directory if not exists 
Python :: add fonts to matplotlib from a particular location 
Python :: print p py pyt pyth pytho python in python 
Python :: python get unique pairs from two lists 
Python :: cannot convert float NaN to integer 
Python :: python remove space from end of string 
Python :: input python 
Python :: calculate distance in python 
Python :: discord.py autorole 
Python :: take screenshot of video python 
Python :: unique_together what is used of it in django 
Python :: pandas look for values in column with condition 
Python :: python convert multidimensional array to one dimensional 
Python :: python json normalize 
Python :: sum all values in a matrix python 
Python :: how to close a flask web server with python 
Python :: DHT22 raspberry pi zero connector 
Python :: cd in python 
Python :: how to remove quotes from a string in python 
Python :: pandas df num rows 
Python :: python find equal rows of two numpy arrays 
Python :: sklearn support vector machine 
Python :: python replace two spaces with one 
Python :: python filter dictionary by keys 
Python :: install python in docker file 
Python :: use matplotlib in python 
Python :: sum first 100 integers in python 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =