Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 problem with class method
#4
(Feb-10-2019, 09:39 PM)snippsat Wrote: As your radius is a default argument,then so can pie be. It can also be be a class attribute with self.pie as @buran suggests.
class Circle: def __init__(self, radius=1, pie=3.14): self.radius = radius self.pie = pie self.area = self.pie * self.radius * self.radius def circum(self): return(2 * self.pie * self.rad
Use:
>>> mycircle = Circle() >>> mycircle.circum() 6.28 >>> # Can change radius,pie is the same as it always has been >>> mycircle = Circle(2) >>> mycircle.circum() 12.56
Also look at PEP-8,for small changes that i made.

Great ... :)
Thanks a lot Bros...it feels awesome getting so much help..
Bundle of thanks both of you @buran, @snippsat
Quote

Top Page

Messages In This Thread
problem with class method - by AmirAB - Feb-10-2019, 08:25 PM
RE: problem with class method - by buran - Feb-10-2019, 08:30 PM
RE: problem with class method - by snippsat - Feb-10-2019, 09:39 PM
RE: problem with class method - by AmirAB - Feb-13-2019, 01:51 AM

Possibly Related Threads...
Thread Author Replies Views Last Post
  What is the use of call method and when to use it? everyday1 1 61 Jul-14-2019, 01:02 PM
Last Post: ichabod801
  Method not defined diskt 1 115 Jul-03-2019, 12:55 PM
Last Post: noisefloor
  Method not regocnized Lass86 3 185 Jun-19-2019, 09:03 AM
Last Post: Lass86
  web3 method rembrandt 3 155 Jun-04-2019, 05:43 PM
Last Post: buran
  Call a varaible from class in the parent class Clement_2000 1 279 May-09-2019, 11:14 PM
Last Post: michalmonday
  Get variable from class inside another class hcne 3 221 Mar-30-2019, 03:02 PM
Last Post: ichabod801
  Why Can't I call base class function for my derived class object? AmirAB 2 255 Feb-13-2019, 03:04 PM
Last Post: snippsat
  why my method doesn't find my List in the same class? Scorpio 2 237 Jan-31-2019, 05:21 PM
Last Post: Scorpio
  Calling a class inside other class dan789 9 496 Jan-06-2019, 02:00 PM
Last Post: dan789
  Class object instance. Link instance attribute to class. Can it be done easier. Windspar 7 493 Dec-03-2018, 11:16 PM
Last Post: Windspar

Forum Jump:


Users browsing this thread: 1 Guest(s)