Strongly typed but variables automatically eclipsed

You are right: one can't pass variables containing integers to functions expecting strings and so on. But there is a confusing point in the tutorial when, few lines after declaring that Python is strongly typed, we can see how it is possible to swap 2 variables containing integer and string respectively.
Later, in this discussion about strength of Python's typing, Poromenos says "In Python you can't assign a string to an integer without doing int("123"), so 3 + "123" is illegal." The example after the comma is right but the statement is at odds with the variable swapping example.

I understood where is the trick thanks to another discussion in this same web-page, about (im)mutability of objects: when you swap those variables, what you actually are doing is creating 2 new variables with the same names as before but with exchanged types. They are not really swapping the value, they are eclipsing previous variables.

I think dynamic creation of variables (without declaration) is much more serious an issue than semantic white-space, which one can solve with a good editor (which is a good thing to have anyway).

Poromenos: I think you can make an example of multiple assignment without mixing things up with eclipsing vars. / changing types and so on. It kept me frowning in wonder for 10 minutes. :-)

Thanks for the tutorial, btw.

Reply

The content of this field is kept private and will not be shown publicly.
Type this to prove you are human.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Ads (you can disable these if you log in)