"Dotan Cohen" <[EMAIL PROTECTED]> 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.

Thus

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.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to