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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:39:39+00:00 2026-06-14T04:39:39+00:00

Ruby supports this: name = name || default If I try it in python:

  • 0

Ruby supports this:

name = name || "default"

If I try it in python:

name = name or "default"

Interpreter reports:

NameError: name 'name' is not defined

What is the equivalent of the short circuit evaluation assignment in python?

  • 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-14T04:39:40+00:00Added an answer on June 14, 2026 at 4:39 am
    name = globals()['name'] if 'name' in globals() else 'default'
    

    or, more succinctly:

    name = globals().get('name','default')
    

    Substitute locals() inside functions.


    Possibly it would be better to just try/except:

    try:
       name
    except NameError:
       name = 'default'
    

    As a side note, I would never use either of these idioms in my code. (Of course, I wouldn’t use the other idioms from Javascript or Ruby that you mentioned). I’d make sure my variables were declared to the default values at the outset and then change them to non-default values as the need arises.

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

Sidebar

Related Questions

I wonder why F-Sharp doesn't support infinity. This would work in Ruby (but not
BerkeleyDB is the database equivalent of a Ruby hashtable or a Python dictionary except
I install plugin open_id_authentication and have this error: /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0.beta/lib/active_support/dependencies.rb:167:in `require': no such file to
I need a cPanel alternative, but with easy deployable Ruby-Rack applications support, not only
Has anybody seen a log file format like this before, or know the name
What is this language construct called? In Python I can say: def a(b,c): return
I know that more-dynamic-than-Java languages, like Python and Ruby, often allow you to place
I tried doing this gem uninstall sqlite3-ruby gem uninstall sqlite3 Then I performed find
There are some batch files in the Ruby installation that reference this Ruby exe
Today the Common Language Run Time Supports Many Languages including Iron Python and Iron

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.