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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:01:53+00:00 2026-05-26T12:01:53+00:00

Over the years I have noticed the ‘wildcard’ variable in various bits and pieces

  • 0

Over the years I have noticed the ‘wildcard’ variable in various bits and pieces of Python I’ve come across. I assumed it worked like Haskell: allowing you to put a variable where one was required in the formal parameters, but not binding it.

I’ve used this on, for example, the left hand side of an tuple-unpacking assignment when I don’t need one of the variables.

For example:

_, extension = os.path.splitext(filename)

So when I wrote something similar to this today:

(lambda (x,_,_): x)((1,2,3))

I.E. I tried to bind the underscore twice, I received a syntax error. I was surprised to see that _ is indeed a real variable:

(lambda (x,_,z): _)((1,2,3))
> 2

Looks like _ is just a variable name like any other.

Is there a bona fide wildcard variable that I can use as I would like (i.e. able to use more than one in a tuple unpacking assignment), as per the first example?

  • 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-05-26T12:01:54+00:00Added an answer on May 26, 2026 at 12:01 pm

    There is no wildcard variable in Python.

    I try to dissuade people from using _ as a variable name for quite some time now. You are not the first person mistaking _ as some kind of special syntax, so it’s better not to use _ as a variable name at all to avoid this kind of confusion. If there ever was a “convention” to use _ as a throw-away variable name, this convention was misguided.

    There are more problems than just the confusion it causes. For example, _ clashes with _ in the interactive interpreter and the common gettext alias.

    Regarding the lambda expression, I’d just use lambda x, *args: ... to ignore all arguments except for the first one. In other cases, I’d use names explicitly stating I don’t want to use them, like dummy. In case of loops of range()s, I usually use for i in range(n) and simply don’t use i.

    Edit: I just noticed (by looking at the other answers) that you use tuple unpacking in the argument list, so lambda x, *args: ... doesn’t solve your problem. Tuple unpacking in parameter lists has been removed in Python 3.x because it was considered too obscure a feature. Better go with mipadi’s answer instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have noticed over the years that different developers have different criteria for what
Modern mobile phones have come far since their beginnings over 30 years ago. Especially
I have a python module that I've been using over the years to process
I'm familiar with the LAMP stack and over the years have successfully deployed a
Over the years I have slowly developed a regular expression that validates most email
Over the years I have vacillated between having my project/source folders in a directory
Our business deals with houses and over the years we have created several business
I've been working on an application for a little over two years and have
Over the years as I have gone through school and been working in the
Over the years most web developers will have built an arsenal of tools or

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.