Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python class getters and setters

class A():
  """Defines a class A with x and y attribute"""
    def __init__(self, x, y):
      """Every instance of A has x and y attributes"""
        self.__x = x #private instance attribute x
        self.__y = y #private instance attribute y
    def GetX(self):
      """Retrieves the x attribute"""
        return self.__x
    def GetY(self):
      """Retrieves the y attribute"""
        return self.__y
    def SetX(self, x):
      """sets the x attribute"""
        self.__x = x
    def SetY(self, y):
      """sets the y attribute"""
        self.__y = y
Comment

Python Class Without Getters and Setters

class Celsius:
    def __init__(self, temperature = 0):
        self.temperature = temperature

    def to_fahrenheit(self):
        return (self.temperature * 1.8) + 32
Comment

PREVIOUS NEXT
Code Example
Python :: Python match.start(), match.end() 
Python :: qrcode how to add logo inside python 
Python :: WARNING: Ignoring invalid distribution -pencv-python 
Python :: numpy subtraction operation using numpy functions 
Python :: How to deal with SettingWithCopyWarning in Pandas 
Python :: Python - pasword hashed 
Python :: In interactive mode, the last printed expression is assigned to the variable _ 
Python :: model summary change size of columns 
Python :: pip package dynamic setup.py example 
Python :: can you use pop on a string 
Python :: for loop python terminal 
Python :: pypy tinytag 
Python :: different accuracy score for knn 
Python :: 0 
Python :: th most effective search methods in python with example 
Python :: django query filter less than 
Python :: how to make change the default from python 3.8 to python 3.10.5 on Mint 20 
Python :: append to multidimensional list python 
Python :: How to Embed a plotly chart in html document 
Python :: install mangadex python 
Python :: pytorch plot batch 
Python :: iterate over batch of dict keys at once python 
Python :: to compare a part of a string to string 
Python :: theano_flags windows 
Python :: python 5 minimal values from array 
Python :: automation script for paytm coupon 
Python :: is python3 enough for react native 
Python :: additon of multiple duration timestamps python 
Python :: red black tree python 
Python :: template strings in python 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =