Python Strings
Erik Max Francis
max at alcyone.com
Wed Sep 6 16:21:54 EDT 2000
Jonadab the Unsightly One wrote:
> I guess that I would still consider a language sufficiently
> "loosely typed"[1] if you can always determine the type of
> an item, as long as you can proceed to assign an entirely
> different item to the same variable a moment later. So
> actually, it's the *variables* that I want to be loosely
> typed, not the language or the objects per se.
Yes, that's dynamic typing, and Python is dynamically typed.
> What I really like is the ability to have an object
> automatically do the appropriate thing with what you
> give it, regardless of what kind of thingy that is.
> This is only possible when you can give it any kind
> of thing that might be appropriate. And in the general
> case, that means you have to be able to give the object
> any kind of thing there is -- a routine, a string,
> a number, or whatever -- and have it be able to know
> what it has (if it needs to know; sometimes it
> doesn't need to know, of course, if it's only passing
> the thingy on to some other object).
Right; this is an element of strong typing, where the type of an object
is an intrinsic property of a type. Compare this with Perl, for
instance, where (scalar) objects do not have any intrinsic type, but are
instead operated on by type-coercing operators (+, ., etc.) that force
the objects to behave as a certain type. For this reason, Perl is
weakly typed, whereas Python is strongly typed.
> In other words, I'm hoping Python has a much-improved
> equivalent for ZRegion. Inform would be better if
> ZRegion (or metaclass) could return a value indicating
> "it's an integer" when that's what it is. This is
> impossible with integers, dictionary words, properties,
> attributes, actions, and assorted other things.
> Fortunately you MOSTLY only need it for strings,
> routines, and objects. But there's always that
> occasion when it'd be nice to do the same thing
> with one of those other types. (Glulx improves
> on this somewhat, I think...)
You can always query the type of a Python object with the type builtin
operator. You can compare it with either a prototype object of the
desired type or one of the predefined types from the types module.
> [1] In the same sense that I say, "I like my languages
> to be loosely typed".
Better than wanting your languages loose, I do suppose.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/ \ You and I / We've seen it all / Chasing our hearts' desire
\__/ The Russian/Florence, _Chess_
Erik Max Francis' bookmarks / http://www.alcyone.com/max/links/
A highly categorized list of Web links.
More information about the Python-list
mailing list