Declaring variables

Matimus mccredie at gmail.com
Wed May 16 19:48:39 EDT 2007


On May 16, 9:57 am, HMS Surprise <j... at datavoiceint.com> wrote:
> I looked in the language but did not find a switch for requiring
> variables to be declared before use.
>
> Is such an option available?
>
> Thanks,
>
> jvh

You do have to declare a variable before use. You do so by assigning
it a value. You can't use a variable before it has been assigned. In
some ways this is less ambiguous than even C where you can declare a
variable without assigning a value. Also note that this caries the
type information, since the variable is of whatever type was assigned
to it. The only thing it doesn't do is give a unique flag that says
"hey this is where I'm declared", although I suppose you could do that
with a comment.

Matt




More information about the Python-list mailing list