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 8640551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:18:26+00:00 2026-06-12T11:18:26+00:00

>>> def itself_and_plusone(x): … return x, x+1 … >>> itself_and_plusone(1) (1, 2) >>> (lambda

  • 0
>>> def itself_and_plusone(x):
...     return x, x+1
... 
>>> itself_and_plusone(1)
(1, 2)

>>> (lambda x: x,x+1)(10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined

why? and workaround with lambda? not by

>>> (lambda x: (x,x+1))(10)
(10, 11)

because it returns a tuple(or list..) and unpacking the tuple would be required

  • 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-12T11:18:28+00:00Added an answer on June 12, 2026 at 11:18 am

    Without the parentheses it is interpreted as follows:

    ((lambda x: x),x+1)(10)
    

    This fails because the second x is outside the lambda expression. And even if x were defined, it would still fail because you can’t use a tuple as if it were a function.

    This simple variation shows what is going on:

    >>> x=42
    >>> (lambda x: x,x+1)
    (<function <lambda> at 0x00000000022B2648>, 43)
    

    Notice that the 43 is because the x in the outer scope is used, not the x in the lambda function.

    The correct way to write it is lambda x: (x,x+1). This does indeed, as you point out, return a tuple, but so does your original function:

    >>> type(itself_and_plusone(10))
    <class 'tuple'>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class HelloWorld(object): def say_it(self): return 'Hello I am Hello World' def i_call_hello_world(hw_obj): print 'here...
def download_if_dne(href, filename): if os.path.isfile(filename): # print 'already downloaded:', href return False else: if
def test_method [a, b, c].map {|i| yield(i) } end If I call test_method like
def self.get(server) return unless server server = server.to_s if klass = @handlers[server] obj =
I have a self-referencing loop that references the most recent associated record to see
mod1.py import mod2 class Universe: def __init__(self): pass def answer(self): return 42 u =
I have a very simple method: Class Team(models.Model): def sides(self): return SideNames.objects.filter(team=self) SideNames is
def self.jq_column_models COLUMN_NAME.collect {|x| {:name => x.to_s, :width => 80, :format => 'integer' if
def On_Instrumentation_StartAnimation(): Syntax : On_Instrumentation_StartAnimation() Purpose : Fired if the animation is started Parameters
def myFunc( a, b ): def innerFunc( c ): print c innerFunc( 2 )

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.