main class:
class circle:
def __init__(self,radius=1):
self.radius=radius
def getArea(self):
return(3.142*self.radius*self.radius)
def getPerimeter(self):
return(2*3.142*self.myradius)
def setradius(self,radius):
if radius>0:
self.__radius=radius
def getRadius(self):
return self.__radius
Using class:
from Circle import circle
def main():
c1=circle()
c1.radius=-1
c2=circle(5)
c3=circle(3)
print(c1.getArea())
print(c2.getArea())
print(c3.getArea())
main()
Hello people!
I was just trying to learn class basics but was haven some trouble. Hope you guys can help. Thanks in advance :)
- What exactly is private variable? I read about it and people say that it cannot be accessed outside of class. OK! BUT WHAT DOES THAT MEAN EXACTLY?
- Is private data same as DATA HIDING?
- What exactly is self? I read about that too but could not understand from previous python answers. From what I think
selfis written after everydefstatement in class.
Thanks again! Cheers!
circleclass is currently not valid/ambiguous -- could you edit your post to fix it?def __init__()needs to be on the same indentation level as the otherdeflines.