Declaring variables
Steve Holden
steve at holdenweb.com
Wed May 16 19:59:17 EDT 2007
Matimus wrote:
> 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.
>
Strictly, the variable has no type at all (and strictly your "variables"
are actually names bound to values in a namespace, and it's the values
that are typed).
We shouldn't ignore the fact that declarations unambiguously say "the
programmer intends to use such-and-such a name for a value of a specific
type". Contrast this with a Python program where one path makes an
assignment (binding) to a name while another path doesn't, resulting in
a later NameError.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------
More information about the Python-list
mailing list