[Tutor] Reformatting phone number
alan.gauld at btinternet.com
Thu Aug 21 00:29:45 CEST 2008
"Dotan Cohen" <dotancohen at gmail.com> wrote
> know if this is the case. Can I declare a variable type in Python as
> in C?
In Python values have types and variables are simply
names associated with values.
v = '123' # v 'is' a string because '123' is a string
v = 123 # now v 'is' an int because 123 is an int.
The variable takes on the type of the value with which it is
associated but it can be made to refer to any other value
and thus its type effectively changes. So it's best not to
think of variables having types but rather consider objects
(or values) as having a type, and variables as being
associated with objects..
This is one of the most fundamental characteristics of
Python and one of the hardest for users of other languages
to adapt to.
Author of the Learn to Program web site
More information about the Tutor