Python Strings

Richard Chamberlain richard_chamberlain at ntlworld.com
Sun Aug 20 03:18:18 EDT 2000


Hi Chris,

fromstr="aslfdj"
tostr=fromstr

Is that what you want?

If you change fromstr to another string tostr will remain pointing at
the first object "aslfdj".

Or you could do something like

tostr=""
tostr.append(fromstr)

strings are immutable so you don't have to worry about putting const in
front of them ;-)

immutable types in python are useful for dictionaries essentially. For a
hashtable to be efficient it requires an unchanging key, so strings fit
this bill.

Richard



CHRIS wrote:
> 
> How can you make a character-by-character copy of one string to a target
> string, with out using a temporary list type variable? IE (with out
> doing somethin like this):
> 
> fromstr = 'aslfdj';
> target = [];
> for i in range(len(fromstr)):
>   #procssing done here
>   target.append(fromstr[i]);
> 
> Also, what's the point of strings being immutable ?? If you want a
> particular variable to be immutable, why not have some sort of constant
> option? Like in C:
> 
> static const char str[] = "Constant immutable string";



More information about the Python-list mailing list