More random python observations from a perl programmer

tim_one at email.msn.com tim_one at email.msn.com
Thu Aug 19 15:33:08 EDT 1999


[duncan at rcp.co.uk (Duncan Booth)]
> :However I agree it can be confusing that when you
> subscript a string you get another object of type string.

[tchrist at mox.perl.com (Tom Christiansen) wrote:]
> *Tell me* about it!
>
>     >>> s = "fred"
>     >>> print s[0]
>     f
>     >>> print s[0][0]
>     f
>     >>> print s[0][0][0]
>     f
>     >>> print s[0][0][0][0]
>     f
>     >>> print s[0][0][0][0][0]
>     f
>     >>> print s[0][0][0][0][0][0]
>     f

Hmm.  I don't see how this differs from the Perl:

$x = "fred";
print substr($x, 0, 1), "\n";
print substr(substr($x, 0, 1), 0, 1), "\n";
print substr(substr(substr($x, 0, 1), 0, 1), 0, 1), "\n";
etc

except-that-python-isn't-so-verbose<wink>-ly y'rs  - tim


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list