Explicit variable declaration

Lie Lie.1296 at gmail.com
Wed Apr 23 12:48:54 EDT 2008


On Apr 23, 4:52 pm, "Filip Gruszczyński" <grusz... at gmail.com> wrote:
> >  You mean the type? Not in 2.x, but in 3.x, there are function
> >  annotations:
>
> >  def a_function(arg1: int, arg2: str) -> None: pass
>
> Nope, I don't like types ;-) 3.x seems pretty revolutionary, and this
> typing can be appreciated by some people.
>
> > Declaring what about them? If you mean declaring the type, remember
> > that Python deliberately allows any name to be bound to any object;
> > type declarations can't be enforced without losing a lot of the power
> > of Python.
>
> Just declaring, that they exist. Saying, that in certain function
> there would appear only specified variables. Like in smalltalk, if I
> remember correctly.

If you want to just declare that name exist, but doesn't want to
declare the type, why don't you just do this:

def somefunc():
    nonlocal = nonlocal
    local = 0 # or None or [] or an initial value
    #
    return nonlocal * local



More information about the Python-list mailing list