basic_python/strings_dicts.rst
author Santosh G. Vattam <vattam.santosh@gmail.com>
Wed, 16 Sep 2009 16:57:49 +0530
changeset 65 0f25f22a2725
child 67 5076574b7b83
permissions -rw-r--r--
Added the strings_dict.rst file.

=======
Strings
=======

Strings were briefly introduced previously in the introduction document. In this
section strings will be presented in greater detail. All the standard operations 
that can be performed on sequences such as indexing, slicing, multiplication, length
minimum and maximum can be performed on string variables as well. One thing to
be noted is that strings are immutable, which means that string variables are
unchangeable. Hence, all item and slice assignments on strings are illegal.
Let us look at a few example.

::

  >>> name = 'PythonFreak'
  >>> print name[3]
  h
  >>> print name[-1]
  k
  >>> print name[6:]
  Freak
  >>> name[6:0] = 'Maniac'
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  TypeError: 'str' object does not support item assignment

This is quite expected, since string objects are immutable as already mentioned.
The error message is clear in mentioning that 'str' object does not support item
assignment.

String Formatting
=================