Python Forum
Practice problem using lambda inside the class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Practice problem using lambda inside the class
#1
I am trying to check if the sum of all 3 sides of triangle is equal to 180 , if it is then it should output true else false,
I am using lamba function to implement it, as i want some practice.
This is what i tried i am getting output as

<function __main__.Triangle.check_angles.<locals>.<lambda>>
instead i should be getting True or False, i really wanna use lamba here, do let me know what i am missing, thanks a lot in advance.

My code here:

class Triangle():
    def  __init__(self, angle1, angle2, angle3):
        self.angle1=angle1 
        self.angle2=angle2
        self.angle3=angle3
        self.number_of_sides=3
    
    def check_angles(self):
        return (lambda self:'True' if (self.angle1+self.angle2+self.angle3)==180 else 'False')

cal=Triangle(45,45,90)
cal.check_angles()
Reply


Messages In This Thread
Practice problem using lambda inside the class - by jagasrik - Sep-12-2020, 12:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  class definition and problem with a method HerrAyas 2 269 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  Best practice on using virtual environments in Python bytecrunch 6 864 Feb-14-2024, 03:22 PM
Last Post: snippsat
  Subclass initialized property used in parent class method. Is it bad coding practice? saavedra29 5 1,804 Feb-07-2022, 07:29 PM
Last Post: saavedra29
  best practice for import libraries and using pyinstaller aster 3 2,890 Apr-17-2021, 11:12 AM
Last Post: snippsat
  How to read file inside class Mekala 11 12,541 May-02-2020, 11:36 AM
Last Post: snippsat
  [split] Python Class Problem astral_travel 12 5,020 Apr-29-2020, 07:13 PM
Last Post: michael1789
  Python Class Problem JPCrosby 2 2,308 Apr-28-2020, 06:18 PM
Last Post: buran
  Threading best practice EvanS1 2 1,948 Apr-21-2020, 10:11 PM
Last Post: EvanS1
  Is it mandatory to call superclass init inside the class init? psolar 3 6,071 Feb-14-2020, 09:16 PM
Last Post: wavic
  Class problem duckduck23 2 2,035 Feb-10-2020, 08:52 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020