Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:27:01+00:00 2026-06-17T20:27:01+00:00

I am studying the properties of functions in Python and I came across an

  • 0

I am studying the properties of functions in Python and I came across an exercise that asks to:

Write a function which returns de power of a number. Conditions: The function may only take 1 argument and must use another function to return the value of the power of a given number.

The code that solves this exercise is:

def power(x):
    return lambda y: y**x

For example, if we would like to know the value of the power: 2^3, we would call the function like this: power(3)(2)

Here is what I would like to know:

Is there any way to write a function that, when called, has a similar structure: function()()().
In other words, is it possible to write a function, that requires three or more parentheses ()()() when called?
If it is possible, could you please give me an example code of that function and briefly explain it?

Also:

def power(x):
    def power_extra(y):
        return y

    def power_another(z):
        return z

    return power_extra and power_another

Possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:27:02+00:00Added an answer on June 17, 2026 at 8:27 pm

    Sure you can:

    def power_times(k):
        """use as power_times(k)(x)(y) => k * y^x"""
        return lambda x: lambda y: k * y**x
    
    print power_times(2)(3)(4)  # returns 2 * 4^3 = 128
    

    When you call this function with argument 2 (power_times(2)), it returns a lambda function that works like lambda x: lambda y: 2 * y ** x (that is, like your original function, only with an extra “times 2”).

    You can stack as many lambdas on top of each other as you like:

    def many_lambdas(x):
        """many_lambdas(x)(y)(z)(q) => x + y * z^q"""
        return lambda y: lambda z: lambda q: x + y * z ** q
    
    print many_lambdas(1)(2)(3)(4) # prints 163
    

    Indeed, it might be even clearer if you skipped using def at all, and just wrote:

    many_lambdas = lambda x: lambda y: lambda z: lambda q: x + y * z ** q
    

    Or, alternatively, you could skip using lambda ever and just use them as nested functions:

    def many_funcs(x):
        def many_funcs_y(y):
            def many_funcs_z(z):
                def many_funcs_q(q):
                    return x + y * z ** q
                return many_funcs_q
            return many_funcs_z
        return many_funcs_y
    
    print many_funcs(1)(2)(3)(4)  # prints 163
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While studying for a Functional Programming exam, I came across the following questions from
While studying for a Functional Programming exam, I came across the following question from
While studying for the Zend PHP Exam I came across the following contradicting information:
studying some sample code from an iOS programming course (cs193p fall2010) i came across
While studying an implementation of Group signature I came across code where Group certificate
Studying Haskell, i'm trying to code a function takeIf that given a condition and
i studying TDateTime functions and procedure, but not found something that allow me to
In studying actionscript 3's graphics class, I've come across the undocumented drawRoundRectComplex() method. It's
After studying TCP/UDP difference all week, I just can't decide which to use. I
While studying computer networks as the course subject, my concept was that operating system

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.