Python variables are bound to types when used?

Simon Brunning simon.brunning at gmail.com
Wed Oct 19 16:07:55 EDT 2005


On 19 Oct 2005 12:51:02 -0700, pranab_bajpai at yahoo.com
<pranab_bajpai at yahoo.com> wrote:
> So I want to define a method that takes a "boolean" in a module, eg.
>
> def getDBName(l2):
> ...
>
> Now, in Python variables are bound to types when used, right?

Python doesn't really have variables as such. It has objects, which
are typed, and names, which are not.

> Eg.
> x = 10 # makes it an INT

The name 'x' is now bound to an int.

> whereas
> x = "hello" # makes it a string

Now it's bound to a string.

> I take it, the parameters to a function (in the above example "l2") are
> bound in the definition, rather than as invoked.
>
> So, if I use "l2" thus:
>
> if (l2): # only then does it make it a boolean?
>
> and if I did,
>
> if (l2 = "hello"): # would it become string?
>
> and what if I never used it in the definition body?

Now you've lost me. Probably my problem - serves me right for posting
from the pub.

> Elucidate please.

I'll allow a true Python Zen master to do that -
<http://effbot.org/zone/python-objects.htm>.

--
Cheers,
Simon B,
simon at brunningonline.net,
http://www.brunningonline.net/simon/blog/



More information about the Python-list mailing list