default variable in python $_

Georg Brandl g.brandl-nospam at gmx.net
Wed Oct 11 00:26:29 CEST 2006


rh0dium wrote:
> Hi all,
> 
> So I have this simple little routine..  say like this..
> 
> 
> def foo()
>    return {"a":"b", "b":"c"}
> 
> if foo():
>    print "Have foo"
> 
> 
> Now I want the dictionary item a (ie. b)
> 
> How can I do it the above way or do I still have to go like this..
> 
> def foo()
>    return {"a":"b", "b":"c"}
> 
> z = foo()
> if z:
>    print "Have foo"
>    print z['a']
> 
> This is where $_ in perl is awesome - There must be a default variable
> in python right?

Why should there? When you're learning a new language, the first thing you
should do is to empty your mind and stop expecting concepts known from other
languages. Instead, try to grasp what the essence of the new language is.

In the case of Python, one credo is "explicit is better than implicit".
IMO, this precludes, among other things, the notion of a "default variable".

Where is the problem with your second snippet?

Georg



More information about the Python-list mailing list