Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help with a Kata
#1
https://www.codewars.com/kata/change-you...ain/python

I don't understand how to pass a callable value into the functions fst and snd. Thanks for your help
Reply
#2
A callable object is a first-class citizen, which means it can be used just like any other object, such as an int. Passing a callable object to a function is then done the same way as with any other object:
def my_func():
    print("called")

def consume(obj):
    if callable(obj):
        return obj()
    return obj

# pass an int
consume(42)

# pass a callable object
consume(my_func)
Reply
#3
IS there a way I can write a function that returns a value and is callable?
def point(a, b):
    f():
        return a, b
    return f
This is callable but doesn't return a or b
def point(a, b):
        return a, b
This returns a and b but is not callable

I need a function that can do both

Reply
#4
(Jul-09-2019, 12:00 AM)Jaccobtw Wrote: This is callable but doesn't return a or b
def point(a, b):
        return a, b

That IS callable, and DOES return both a and b.
Reply


Forum Jump:

User Panel Messages

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