summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSantosh G. Vattam2009-09-16 16:57:49 +0530
committerSantosh G. Vattam2009-09-16 16:57:49 +0530
commit7cbd66266f5611c250c4f7e87ccdfdbf910c6777 (patch)
treed8cfc6319cdb1a3d070d5f7f80350bd2e25ea198
parentb1f75b889e87b06220435c85632e7674599f56c2 (diff)
downloadsees-7cbd66266f5611c250c4f7e87ccdfdbf910c6777.tar.gz
sees-7cbd66266f5611c250c4f7e87ccdfdbf910c6777.tar.bz2
sees-7cbd66266f5611c250c4f7e87ccdfdbf910c6777.zip
Added the strings_dict.rst file.
-rw-r--r--basic_python/intro.rst12
-rw-r--r--basic_python/strings_dicts.rst33
2 files changed, 39 insertions, 6 deletions
diff --git a/basic_python/intro.rst b/basic_python/intro.rst
index 7ae98d8..56c30e2 100644
--- a/basic_python/intro.rst
+++ b/basic_python/intro.rst
@@ -543,7 +543,8 @@ Let us look at examples:
False
The **while** loop
-~~~~~~~~~~~~~~~~~~
+==================
+
The Python **while** loop is similar to the C/C++ while loop. The syntax is as
follows:
@@ -572,7 +573,7 @@ Let us look at an example:
5
The **if** conditional
-~~~~~~~~~~~~~~~~~~~~~~
+======================
The Python **if** block provides the conditional execution of statements.
If the condition evaluates as true the block of statements defined under the if
@@ -612,7 +613,7 @@ Let us look at an example:
print n, " is 0"
**raw_input()**
-~~~~~~~~~~~~~~~
+===============
In the previous example we saw the call to the raw_input() subroutine.
The **raw_input()** method is used to take user inputs through the console.
@@ -685,7 +686,7 @@ Observe here that the variable *pal* is a string and hence integer operations
cannot be performed on it. Hence the exception is raised.
**int()** method
-~~~~~~~~~~~~~~~~
+================
Generally for computing purposes, the data used is not strings or raw data but
on integers, floats and similar mathematical data structures. The data obtained
@@ -715,7 +716,7 @@ using the **int()** method the string *pal* was converted to an integer variable
Functions in Python: **def**
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+============================
*Functions* allow us to enclose a set of statements and call the function again
and again instead of repeating the group of statements everytime. Functions also
@@ -809,7 +810,6 @@ the values are manipulated even outside the function::
>>> can_change(name)
>>> name
['Mr.', 'James', 'Gosling']
-
If nothing is returned by the function explicitly, Python takes care to return
None when the funnction is called.
diff --git a/basic_python/strings_dicts.rst b/basic_python/strings_dicts.rst
new file mode 100644
index 0000000..1a79b3a
--- /dev/null
+++ b/basic_python/strings_dicts.rst
@@ -0,0 +1,33 @@
+=======
+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
+=================
+