SEESenv/web/html/ch4strings_dicts.html
author amit@thunder
Thu, 25 Feb 2010 00:04:27 +0530
changeset 27 cb14131583c6
parent 25 ed38dd9bdb50
child 28 514098969b11
permissions -rw-r--r--
Started on final changes to the build scripts so that we can start with totally automatic builds
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     1
<html>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
     2
 <head>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
     3
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
     4
  <title>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
     5
   Chapter. strings_dicts
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
     6
  </title>
15
f2383fee6584 Testing
amit@thunder
parents: 6
diff changeset
     7
  <link rel="stylesheet" href="/review/support/styles.css" type="text/css" />
f2383fee6584 Testing
amit@thunder
parents: 6
diff changeset
     8
  <meta name="generator" content="DocBook XSL Stylesheets V1.74.3" />
f2383fee6584 Testing
amit@thunder
parents: 6
diff changeset
     9
  <link rel="shortcut icon" type="image/png" href="/review/support/figs/favicon.png" />
f2383fee6584 Testing
amit@thunder
parents: 6
diff changeset
    10
  <script type="text/javascript" src="/review/support/jquery-min.js">
f2383fee6584 Testing
amit@thunder
parents: 6
diff changeset
    11
  </script>
f2383fee6584 Testing
amit@thunder
parents: 6
diff changeset
    12
  <script type="text/javascript" src="/review/support/form.js">
f2383fee6584 Testing
amit@thunder
parents: 6
diff changeset
    13
  </script>
f2383fee6584 Testing
amit@thunder
parents: 6
diff changeset
    14
  <script type="text/javascript" src="/review/support/hsbook.js">
f2383fee6584 Testing
amit@thunder
parents: 6
diff changeset
    15
  </script>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    16
 </head>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    17
 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
16
2e3d2cadbcb6 Testing
amit@thunder
parents: 15
diff changeset
    18
  <div class="chapter" id="ch4strings_dicts">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    19
   <div class="titlepage">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    20
   </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    21
   <div class="toc">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    22
    <p>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    23
     <b>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    24
      Table of Contents
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    25
     </b>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    26
    </p>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    27
    <dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    28
     <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    29
      <span class="article">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
    30
       <a href="#id2580313">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    31
        Strings
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    32
       </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    33
      </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    34
     </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    35
     <dd>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    36
      <dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    37
       <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    38
        <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
    39
         <a href="#id2578900">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    40
          1. String Formatting
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    41
         </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    42
        </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    43
       </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    44
       <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    45
        <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
    46
         <a href="#id2631317">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    47
          2. String Methods
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    48
         </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    49
        </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    50
       </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    51
       <dd>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    52
        <dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    53
         <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    54
          <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
    55
           <a href="#id2631332">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    56
            2.1.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    57
            <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    58
             <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    59
              find
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    60
             </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    61
            </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    62
           </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    63
          </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    64
         </dt>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    65
         <dt>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    66
          <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
    67
           <a href="#id2631362">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    68
            2.2.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    69
            <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    70
             <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    71
              join
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    72
             </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    73
            </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    74
           </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    75
          </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    76
         </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    77
         <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    78
          <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
    79
           <a href="#id2631402">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    80
            2.3.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    81
            <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    82
             <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    83
              lower
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    84
             </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    85
            </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    86
           </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    87
          </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    88
         </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    89
         <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    90
          <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
    91
           <a href="#id2631432">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    92
            2.4.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    93
            <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    94
             <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    95
              replace
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    96
             </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
    97
            </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    98
           </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
    99
          </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   100
         </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   101
         <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   102
          <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   103
           <a href="#id2631489">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   104
            2.5.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   105
            <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   106
             <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   107
              split
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   108
             </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   109
            </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   110
           </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   111
          </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   112
         </dt>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   113
         <dt>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   114
          <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   115
           <a href="#id2631548">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   116
            2.6.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   117
            <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   118
             <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   119
              strip
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   120
             </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   121
            </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   122
           </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   123
          </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   124
         </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   125
        </dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   126
       </dd>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   127
       <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   128
        <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   129
         <a href="#id2631592">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   130
          3. Introduction to the standard library
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   131
         </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   132
        </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   133
       </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   134
       <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   135
        <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   136
         <a href="#id2631669">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   137
          4. I/O: Reading and Writing Files
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   138
         </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   139
        </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   140
       </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   141
       <dd>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   142
        <dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   143
         <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   144
          <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   145
           <a href="#id2631699">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   146
            4.1. Opening Files
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   147
           </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   148
          </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   149
         </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   150
         <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   151
          <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   152
           <a href="#id2631873">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   153
            4.2. Reading and Writing files
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   154
           </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   155
          </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   156
         </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   157
        </dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   158
       </dd>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   159
       <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   160
        <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   161
         <a href="#id2632038">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   162
          5. Dictionaries
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   163
         </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   164
        </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   165
       </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   166
       <dd>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   167
        <dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   168
         <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   169
          <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   170
           <a href="#id2632094">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   171
            5.1.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   172
            <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   173
             <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   174
              dict()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   175
             </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   176
            </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   177
           </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   178
          </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   179
         </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   180
         <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   181
          <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   182
           <a href="#id2632158">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   183
            5.2. Dictionary Methods
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   184
           </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   185
          </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   186
         </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   187
        </dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   188
       </dd>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   189
      </dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   190
     </dd>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   191
    </dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   192
   </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   193
   <div class="article" title="Strings">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   194
    <div class="titlepage">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   195
     <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   196
      <div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   197
       <h2 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   198
        <a name="id2580313">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   199
        </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   200
        Strings
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   201
       </h2>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   202
      </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   203
     </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   204
     <hr />
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   205
    </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   206
    <div class="toc">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   207
     <p>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   208
      <b>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   209
       Table of Contents
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   210
      </b>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   211
     </p>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   212
     <dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   213
      <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   214
       <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   215
        <a href="#id2578900">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   216
         1. String Formatting
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   217
        </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   218
       </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   219
      </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   220
      <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   221
       <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   222
        <a href="#id2631317">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   223
         2. String Methods
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   224
        </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   225
       </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   226
      </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   227
      <dd>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   228
       <dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   229
        <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   230
         <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   231
          <a href="#id2631332">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   232
           2.1.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   233
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   234
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   235
             find
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   236
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   237
           </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   238
          </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   239
         </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   240
        </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   241
        <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   242
         <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   243
          <a href="#id2631362">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   244
           2.2.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   245
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   246
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   247
             join
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   248
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   249
           </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   250
          </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   251
         </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   252
        </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   253
        <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   254
         <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   255
          <a href="#id2631402">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   256
           2.3.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   257
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   258
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   259
             lower
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   260
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   261
           </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   262
          </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   263
         </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   264
        </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   265
        <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   266
         <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   267
          <a href="#id2631432">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   268
           2.4.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   269
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   270
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   271
             replace
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   272
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   273
           </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   274
          </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   275
         </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   276
        </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   277
        <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   278
         <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   279
          <a href="#id2631489">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   280
           2.5.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   281
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   282
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   283
             split
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   284
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   285
           </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   286
          </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   287
         </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   288
        </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   289
        <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   290
         <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   291
          <a href="#id2631548">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   292
           2.6.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   293
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   294
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   295
             strip
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   296
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   297
           </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   298
          </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   299
         </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   300
        </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   301
       </dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   302
      </dd>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   303
      <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   304
       <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   305
        <a href="#id2631592">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   306
         3. Introduction to the standard library
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   307
        </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   308
       </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   309
      </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   310
      <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   311
       <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   312
        <a href="#id2631669">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   313
         4. I/O: Reading and Writing Files
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   314
        </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   315
       </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   316
      </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   317
      <dd>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   318
       <dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   319
        <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   320
         <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   321
          <a href="#id2631699">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   322
           4.1. Opening Files
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   323
          </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   324
         </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   325
        </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   326
        <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   327
         <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   328
          <a href="#id2631873">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   329
           4.2. Reading and Writing files
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   330
          </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   331
         </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   332
        </dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   333
       </dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   334
      </dd>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   335
      <dt>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   336
       <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   337
        <a href="#id2632038">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   338
         5. Dictionaries
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   339
        </a>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   340
       </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   341
      </dt>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   342
      <dd>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   343
       <dl>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   344
        <dt>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   345
         <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   346
          <a href="#id2632094">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   347
           5.1.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   348
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   349
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   350
             dict()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   351
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   352
           </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   353
          </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   354
         </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   355
        </dt>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   356
        <dt>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   357
         <span class="section">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   358
          <a href="#id2632158">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   359
           5.2. Dictionary Methods
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   360
          </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   361
         </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   362
        </dt>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   363
       </dl>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   364
      </dd>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   365
     </dl>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   366
    </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   367
    <p id="ch4strings_dicts_1">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   368
     Strings were briefly introduced previously in the introduction document. In this
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   369
section strings will be presented in greater detail. All the standard operations
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   370
that can be performed on sequences such as indexing, slicing, multiplication, length
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   371
minimum and maximum can be performed on string variables as well. One thing to
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   372
be noted is that strings are immutable, which means that string variables are
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   373
unchangeable. Hence, all item and slice assignments on strings are illegal.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   374
Let us look at a few example.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   375
    </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   376
    <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   377
     &gt;&gt;&gt; name = 'PythonFreak'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   378
&gt;&gt;&gt; print name[3]
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   379
h
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   380
&gt;&gt;&gt; print name[-1]
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   381
k
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   382
&gt;&gt;&gt; print name[6:]
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   383
Freak
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   384
&gt;&gt;&gt; name[6:0] = 'Maniac'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   385
Traceback (most recent call last):
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   386
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   387
TypeError: 'str' object does not support item assignment
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   388
    </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   389
    <p id="ch4strings_dicts_2">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   390
     This is quite expected, since string objects are immutable as already mentioned.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   391
The error message is clear in mentioning that 'str' object does not support item
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   392
assignment.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   393
    </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   394
    <div class="section" title="1.String Formatting">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   395
     <div class="titlepage">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   396
      <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   397
       <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   398
        <h2 class="title" style="clear: both">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   399
         <a name="id2578900">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   400
         </a>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   401
         1.String Formatting
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   402
        </h2>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   403
       </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   404
      </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   405
     </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   406
     <p id="ch4strings_dicts_3">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   407
      String formatting can be performed using the string formatting operator represented
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   408
as the percent (%) sign. The string placed before the % sign is formatted with
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   409
the value placed to the right of it. Let us look at a simple example.
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   410
     </p>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   411
     <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   412
      &gt;&gt;&gt; format = 'Hello %s, from PythonFreak'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   413
&gt;&gt;&gt; str1 = 'world!'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   414
&gt;&gt;&gt; print format % str1
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   415
Hello world!, from PythonFreak
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   416
     </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   417
     <p id="ch4strings_dicts_4">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   418
      The %s parts of the format string are called the coversion specifiers. The coversion
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   419
specifiers mark the places where the formatting has to be performed in a string.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   420
In the example the %s is replaced by the value of str1. More than one value can
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   421
also be formatted at a time by specifying the values to be formatted using tuples
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   422
and dictionaries (explained in later sections). Let us look at an example.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   423
     </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   424
     <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   425
      &gt;&gt;&gt; format = 'Hello %s, from %s'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   426
&gt;&gt;&gt; values = ('world!', 'PythonFreak')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   427
&gt;&gt;&gt; print format % values
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   428
Hello world!, from PythonFreak
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   429
     </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   430
     <p id="ch4strings_dicts_5">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   431
      In this example it can be observed that the format string contains two conversion
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   432
specifiers and they are formatted using the tuple of values as shown.
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   433
     </p>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   434
     <p id="ch4strings_dicts_6">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   435
      The s in %s specifies that the value to be replaced is of type string. Values of
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   436
other types can be specified as well such as integers and floats. Integers are
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   437
specified as %d and floats as %f. The precision with which the integer or the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   438
float values are to be represented can also be specified using a
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   439
      <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   440
       <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   441
        .
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   442
       </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   443
      </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   444
      (
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   445
      <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   446
       <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   447
        dot
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   448
       </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   449
      </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   450
      )
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   451
followed by the precision value.
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   452
     </p>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   453
    </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   454
    <div class="section" title="2.String Methods">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   455
     <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   456
      <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   457
       <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   458
        <h2 class="title" style="clear: both">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   459
         <a name="id2631317">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   460
         </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   461
         2.String Methods
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   462
        </h2>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   463
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   464
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   465
     </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   466
     <p id="ch4strings_dicts_7">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   467
      Similar to list methods, strings also have a rich set of methods to perform various
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   468
operations on strings. Some of the most important and popular ones are presented
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   469
in this section.
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   470
     </p>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   471
     <div class="section" title="2.1.find">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   472
      <div class="titlepage">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   473
       <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   474
        <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   475
         <h3 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   476
          <a name="id2631332">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   477
          </a>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   478
          2.1.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   479
          <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   480
           <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   481
            find
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   482
           </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   483
          </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   484
         </h3>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   485
        </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   486
       </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   487
      </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   488
      <p id="ch4strings_dicts_8">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   489
       The
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   490
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   491
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   492
         find
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   493
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   494
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   495
       method is used to search for a substring within a given string. It
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   496
returns the left most index of the first occurence of the substring. If the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   497
substring is not found in the string then it returns -1. Let us look at a few
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   498
examples.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   499
      </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   500
      <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   501
       &gt;&gt;&gt; longstring = 'Hello world!, from PythonFreak'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   502
&gt;&gt;&gt; longstring.find('Python')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   503
19
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   504
&gt;&gt;&gt; longstring.find('Perl')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   505
-1
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   506
      </pre>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   507
     </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   508
     <div class="section" title="2.2.join">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   509
      <div class="titlepage">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   510
       <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   511
        <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   512
         <h3 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   513
          <a name="id2631362">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   514
          </a>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   515
          2.2.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   516
          <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   517
           <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   518
            join
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   519
           </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   520
          </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   521
         </h3>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   522
        </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   523
       </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   524
      </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   525
      <p id="ch4strings_dicts_9">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   526
       The
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   527
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   528
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   529
         join
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   530
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   531
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   532
       method is used to join the elements of a sequence. The sequence
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   533
elements that are to be join ed should all be strings. Let us look at a few
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   534
examples.
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   535
      </p>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   536
      <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   537
       &gt;&gt;&gt; seq = ['With', 'great', 'power', 'comes', 'great', 'responsibility']
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   538
&gt;&gt;&gt; sep = ' '
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   539
&gt;&gt;&gt; sep.join(seq)
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   540
'With great power comes great responsibility'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   541
&gt;&gt;&gt; sep = ',!'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   542
&gt;&gt;&gt; sep.join(seq)
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   543
'With,!great,!power,!comes,!great,!responsibility'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   544
      </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   545
      <p id="ch4strings_dicts_a">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   546
       <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   547
        <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   548
         Try this yourself
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   549
        </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   550
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   551
      </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   552
      <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   553
       &gt;&gt;&gt; seq = [12,34,56,78]
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   554
&gt;&gt;&gt; sep.join(seq)
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   555
      </pre>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   556
     </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   557
     <div class="section" title="2.3.lower">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   558
      <div class="titlepage">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   559
       <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   560
        <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   561
         <h3 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   562
          <a name="id2631402">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   563
          </a>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   564
          2.3.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   565
          <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   566
           <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   567
            lower
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   568
           </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   569
          </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   570
         </h3>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   571
        </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   572
       </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   573
      </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   574
      <p id="ch4strings_dicts_b">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   575
       The
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   576
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   577
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   578
         lower
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   579
        </strong>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   580
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   581
       method, as the name indicates, converts the entire text of a string
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   582
to lower case. It is specially useful in cases where the programmers deal with case
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   583
insensitive data. Let us look at a few examples.
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   584
      </p>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   585
      <pre class="programlisting">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   586
       &gt;&gt;&gt; sometext = 'Hello world!, from PythonFreak'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   587
&gt;&gt;&gt; sometext.lower()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   588
'hello world!, from pythonfreak'
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   589
      </pre>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   590
     </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   591
     <div class="section" title="2.4.replace">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   592
      <div class="titlepage">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   593
       <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   594
        <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   595
         <h3 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   596
          <a name="id2631432">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   597
          </a>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   598
          2.4.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   599
          <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   600
           <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   601
            replace
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   602
           </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   603
          </span>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   604
         </h3>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   605
        </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   606
       </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   607
      </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   608
      <p id="ch4strings_dicts_c">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   609
       The
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   610
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   611
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   612
         replace
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   613
        </strong>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   614
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   615
       method replaces a substring with another substring within
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   616
a given string and returns the new string. Let us look at an example.
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   617
      </p>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   618
      <pre class="programlisting">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   619
       &gt;&gt;&gt; sometext = 'Concise, precise and criticise is some of the words that end with ise'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   620
&gt;&gt;&gt; sometext.replace('is', 'are')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   621
'Concaree, precaree and criticaree are some of the words that end with aree'
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   622
      </pre>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   623
      <p id="ch4strings_dicts_d">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   624
       Observe here that all the occurences of the substring
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   625
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   626
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   627
         is
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   628
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   629
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   630
       have been replaced,
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   631
even the
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   632
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   633
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   634
         is
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   635
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   636
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   637
       in
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   638
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   639
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   640
         concise
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   641
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   642
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   643
       ,
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   644
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   645
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   646
         precise
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   647
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   648
       </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   649
       and
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   650
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   651
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   652
         criticise
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   653
        </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   654
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   655
       have been replaced.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   656
      </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   657
     </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   658
     <div class="section" title="2.5.split">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   659
      <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   660
       <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   661
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   662
         <h3 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   663
          <a name="id2631489">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   664
          </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   665
          2.5.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   666
          <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   667
           <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   668
            split
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   669
           </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   670
          </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   671
         </h3>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   672
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   673
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   674
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   675
      <p id="ch4strings_dicts_e">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   676
       The
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   677
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   678
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   679
         split
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   680
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   681
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   682
       is one of the very important string methods. split is the opposite of the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   683
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   684
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   685
         join
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   686
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   687
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   688
       method. It is used to split a string based on the argument passed as the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   689
delimiter. It returns a list of strings. By default when no argument is passed it
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   690
splits with
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   691
       <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   692
        <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   693
         space
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   694
        </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   695
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   696
       (' ') as the delimiter. Let us look at an example.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   697
      </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   698
      <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   699
       &gt;&gt;&gt; grocerylist = 'butter, cucumber, beer(a grocery item??), wheatbread'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   700
&gt;&gt;&gt; grocerylist.split(',')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   701
['butter', ' cucumber', ' beer(a grocery item??)', ' wheatbread']
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   702
&gt;&gt;&gt; grocerylist.split()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   703
['butter,', 'cucumber,', 'beer(a', 'grocery', 'item??),', 'wheatbread']
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   704
      </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   705
      <p id="ch4strings_dicts_f">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   706
       Observe here that in the second case when the delimiter argument was not set
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   707
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   708
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   709
         split
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   710
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   711
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   712
       was done with
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   713
       <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   714
        <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   715
         space
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   716
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   717
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   718
       as the delimiter.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   719
      </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   720
     </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   721
     <div class="section" title="2.6.strip">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   722
      <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   723
       <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   724
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   725
         <h3 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   726
          <a name="id2631548">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   727
          </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   728
          2.6.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   729
          <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   730
           <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   731
            strip
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   732
           </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   733
          </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   734
         </h3>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   735
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   736
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   737
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   738
      <p id="ch4strings_dicts_10">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   739
       The
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   740
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   741
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   742
         strip
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   743
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   744
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   745
       method is used to remove or
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   746
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   747
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   748
         strip
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   749
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   750
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   751
       off any whitespaces that exist
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   752
to the left and right of a string, but not the whitespaces within a string. Let
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   753
us look at an example.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   754
      </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   755
      <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   756
       &gt;&gt;&gt; spacedtext = "               Where's the text??                 "
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   757
&gt;&gt;&gt; spacedtext.strip()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   758
"Where's the text??"
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   759
      </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   760
      <p id="ch4strings_dicts_11">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   761
       Observe that the whitespaces between the words have not been removed.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   762
      </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   763
      <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   764
       Note: Very important thing to note is that all the methods shown above do not
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   765
      transform the source string. The source string still remains the same.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   766
      Remember that **strings are immutable**.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   767
      </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   768
     </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   769
    </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   770
    <div class="section" title="3.Introduction to the standard library">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   771
     <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   772
      <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   773
       <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   774
        <h2 class="title" style="clear: both">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   775
         <a name="id2631592">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   776
         </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   777
         3.Introduction to the standard library
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   778
        </h2>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   779
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   780
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   781
     </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   782
     <p id="ch4strings_dicts_12">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   783
      Python is often referred to as a "Batteries included!" language, mainly because
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   784
of the Python Standard Library. The Python Standard Library provides an extensive
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   785
set of features some of which are available directly for use while some require to
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   786
import a few
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   787
      <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   788
       <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   789
        modules
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   790
       </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   791
      </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   792
      . The Standard Library provides various built-in functions
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   793
like:
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   794
     </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   795
     <div class="itemizedlist">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   796
      <ul class="itemizedlist" type="*">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   797
       <li class="listitem" style="list-style-type: *">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   798
        <p id="ch4strings_dicts_13">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   799
         <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   800
          <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   801
           abs()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   802
          </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   803
         </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   804
        </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   805
       </li>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   806
       <li class="listitem" style="list-style-type: *">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   807
        <p id="ch4strings_dicts_14">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   808
         <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   809
          <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   810
           dict()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   811
          </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   812
         </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   813
        </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   814
       </li>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   815
       <li class="listitem" style="list-style-type: *">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   816
        <p id="ch4strings_dicts_15">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   817
         <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   818
          <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   819
           enumerate()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   820
          </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   821
         </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   822
        </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   823
       </li>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   824
      </ul>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   825
     </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   826
     <p id="ch4strings_dicts_16">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   827
      The built-in constants like
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   828
      <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   829
       <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   830
        True
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   831
       </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   832
      </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   833
      and
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   834
      <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   835
       <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   836
        False
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   837
       </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   838
      </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   839
      are provided by the Standard Library.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   840
More information about the Python Standard Library is available
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   841
     </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   842
     <div class="reference">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   843
      <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   844
       <hr />
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   845
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   846
      http://docs.python.org/library/
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   847
     </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   848
    </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   849
    <div class="section" title="4.I/O: Reading and Writing Files">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   850
     <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   851
      <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   852
       <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   853
        <h2 class="title" style="clear: both">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   854
         <a name="id2631669">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   855
         </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   856
         4.I/O: Reading and Writing Files
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   857
        </h2>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   858
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   859
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   860
     </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   861
     <p id="ch4strings_dicts_17">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   862
      Files are very important aspects when it comes to computing and programming.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   863
Up until now the focus has been on small programs that interacted with users
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   864
through
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   865
      <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   866
       <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   867
        input()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   868
       </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   869
      </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   870
      and
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   871
      <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   872
       <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   873
        raw_input()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   874
       </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   875
      </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   876
      . Generally, for computational purposes
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   877
it becomes necessary to handle files, which are usually large in size as well.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   878
This section focuses on basics of file handling.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   879
     </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   880
     <div class="section" title="4.1.Opening Files">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   881
      <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   882
       <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   883
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   884
         <h3 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
   885
          <a name="id2631699">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   886
          </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   887
          4.1.Opening Files
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   888
         </h3>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   889
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   890
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   891
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   892
      <p id="ch4strings_dicts_18">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   893
       Files can be opened using the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   894
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   895
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   896
         open()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   897
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   898
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   899
       method.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   900
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   901
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   902
         open()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   903
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   904
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   905
       accepts 3 arguments
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   906
out of which 2 are optional. Let us look at the syntax of
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   907
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   908
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   909
         open()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   910
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   911
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   912
       :
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   913
      </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   914
      <p id="ch4strings_dicts_19">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   915
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   916
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   917
         f = open( filename, mode, buffering)
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   918
        </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   919
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   920
      </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   921
      <p id="ch4strings_dicts_1a">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   922
       The
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   923
       <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   924
        <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   925
         filename
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   926
        </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   927
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   928
       is a compulsory argument while the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   929
       <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   930
        <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   931
         mode
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   932
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   933
       </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   934
       and
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   935
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   936
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   937
         buffering
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   938
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   939
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   940
       are
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   941
optional. The
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   942
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   943
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   944
         filename
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   945
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   946
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   947
       should be a string and it should be the complete path
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   948
to the file to be opened (The path can be absolute or relative). Let us look at
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   949
an example.
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   950
      </p>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   951
      <pre class="programlisting">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   952
       &gt;&gt;&gt; f = open ('basic_python/interim_assessment.rst')
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   953
      </pre>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   954
      <p id="ch4strings_dicts_1b">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   955
       The
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   956
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   957
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   958
         mode
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   959
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   960
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   961
       argument specifies the mode in which the file has to be opened.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   962
The following are the valid mode arguments:
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   963
      </p>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   964
      <p id="ch4strings_dicts_1c">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   965
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   966
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   967
         r
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   968
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   969
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   970
       - Read mode
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   971
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   972
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   973
         w
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   974
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   975
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   976
       - Write mode
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   977
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   978
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   979
         a
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   980
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   981
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   982
       - Append mode
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   983
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   984
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   985
         b
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   986
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   987
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   988
       - Binary mode
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   989
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   990
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   991
         +
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   992
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   993
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   994
       - Read/Write mode
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
   995
      </p>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   996
      <p id="ch4strings_dicts_1d">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   997
       The read mode opens the file as a read-only document. The write mode opens the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   998
file in the Write only mode. In the write mode, if the file existed prior to the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   999
opening, the previous contents of the file are erased. The append mode opens the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1000
file in the write mode but the previous contents of the file are not erased and
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1001
the current data is appended onto the file.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1002
The binary and the read/write modes are special in the sense that they are added
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1003
onto other modes. The read/write mode opens the file in the reading and writing
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1004
mode combined. The binary mode can be used to open a files that do not contain
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1005
text. Binary files such as images should be opened in the binary mode. Let us look
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1006
at a few examples.
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1007
      </p>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1008
      <pre class="programlisting">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1009
       &gt;&gt;&gt; f = open ('basic_python/interim_assessment.rst', 'r')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1010
&gt;&gt;&gt; f = open ('armstrong.py', 'r+')
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1011
      </pre>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1012
      <p id="ch4strings_dicts_1e">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1013
       The third argument to the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1014
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1015
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1016
         open()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1017
        </strong>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1018
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1019
       method is the
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1020
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1021
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1022
         buffering
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1023
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1024
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1025
       argument. This takes
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1026
a boolean value,
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1027
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1028
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1029
         True
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1030
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1031
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1032
       or
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1033
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1034
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1035
         1
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1036
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1037
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1038
       indicates that buffering has to be enabled on the file,
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1039
that is the file is loaded on to the main memory and the changes made to the file are
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1040
not immediately written to the disk. If the
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1041
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1042
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1043
         buffering
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1044
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1045
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1046
       argument is
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1047
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1048
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1049
         0
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1050
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1051
       </span>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1052
       or
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1053
       <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1054
        <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1055
         False
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1056
        </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1057
       </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1058
       the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1059
changes are directly written on to the disk immediately.
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1060
      </p>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1061
     </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1062
     <div class="section" title="4.2.Reading and Writing files">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1063
      <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1064
       <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1065
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1066
         <h3 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1067
          <a name="id2631873">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1068
          </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1069
          4.2.Reading and Writing files
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1070
         </h3>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1071
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1072
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1073
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1074
      <div class="section" title="4.2.1.write()">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1075
       <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1076
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1077
         <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1078
          <h4 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1079
           <a name="id2631882">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1080
           </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1081
           4.2.1.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1082
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1083
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1084
             write()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1085
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1086
           </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1087
          </h4>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1088
         </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1089
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1090
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1091
       <p id="ch4strings_dicts_1f">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1092
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1093
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1094
          write()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1095
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1096
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1097
        , evidently, is used to write data onto a file. It takes the data to
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1098
be written as the argument. The data can be a string, an integer, a float or any
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1099
other datatype. In order to be able to write data onto a file, the file has to
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1100
be opened in one of
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1101
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1102
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1103
          w
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1104
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1105
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1106
        ,
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1107
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1108
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1109
          a
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1110
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1111
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1112
        or
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1113
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1114
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1115
          +
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1116
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1117
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1118
        modes.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1119
       </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1120
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1121
      <div class="section" title="4.2.2.read()">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1122
       <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1123
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1124
         <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1125
          <h4 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1126
           <a name="id2631921">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1127
           </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1128
           4.2.2.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1129
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1130
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1131
             read()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1132
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1133
           </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1134
          </h4>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1135
         </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1136
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1137
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1138
       <p id="ch4strings_dicts_20">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1139
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1140
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1141
          read()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1142
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1143
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1144
        is used to read data from a file. It takes the number of bytes of data
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1145
to be read as the argument. If nothing is specified by default it reads the entire
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1146
contents from the current position to the end of file.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1147
       </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1148
       <p id="ch4strings_dicts_21">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1149
        Let us look at a few examples:
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1150
       </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1151
       <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1152
        &gt;&gt;&gt; f = open ('randomtextfile', 'w')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1153
&gt;&gt;&gt; f.write('Hello all, this is PythonFreak. This is a random text file.')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1154
&gt;&gt;&gt; f = open ('../randomtextfile', 'r')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1155
&gt;&gt;&gt; f = open ('../randomtextfile', 'r')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1156
&gt;&gt;&gt; f.read(5)
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1157
'Hello'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1158
&gt;&gt;&gt; f.read()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1159
' all, this is PythonFreak. This is a random text file.'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1160
&gt;&gt;&gt; f.close()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1161
       </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1162
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1163
      <div class="section" title="4.2.3.readline()">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1164
       <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1165
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1166
         <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1167
          <h4 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1168
           <a name="id2631956">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1169
           </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1170
           4.2.3.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1171
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1172
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1173
             readline()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1174
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1175
           </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1176
          </h4>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1177
         </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1178
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1179
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1180
       <p id="ch4strings_dicts_22">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1181
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1182
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1183
          readline()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1184
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1185
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1186
        is used to read a file line by line.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1187
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1188
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1189
          readline()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1190
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1191
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1192
        reads a line
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1193
of a file at a time. When an argument is passed to
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1194
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1195
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1196
          readline()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1197
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1198
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1199
        it reads that
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1200
many bytes from the current line.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1201
       </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1202
       <p id="ch4strings_dicts_23">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1203
        One other method to read a file line by line is using the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1204
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1205
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1206
          read()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1207
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1208
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1209
        and the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1210
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1211
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1212
          for
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1213
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1214
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1215
        construct. Let us look at this block of code as an example.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1216
       </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1217
       <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1218
        &gt;&gt;&gt; f = open('../randomtextfile', 'r')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1219
&gt;&gt;&gt; for line in f:
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1220
...     print line
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1221
...
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1222
Hello all!
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1223
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1224
This is PythonFreak on the second line.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1225
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1226
This is a random text file on line 3
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1227
       </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1228
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1229
      <div class="section" title="4.2.4.close()">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1230
       <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1231
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1232
         <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1233
          <h4 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1234
           <a name="id2632015">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1235
           </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1236
           4.2.4.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1237
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1238
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1239
             close()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1240
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1241
           </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1242
          </h4>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1243
         </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1244
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1245
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1246
       <p id="ch4strings_dicts_24">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1247
        One must always close all the files that have been opened. Although, files opened
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1248
will be closed automatically when the program ends. When files opened in read mode
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1249
are not closed it might lead to uselessly locked sometimes. In case of files
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1250
opened in the write mode it is more important to close the files. This is because,
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1251
Python maybe using the file in the buffering mode and when the file is not closed
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1252
the buffer maybe lost completely and the changes made to the file are lost forever.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1253
       </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1254
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1255
     </div>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1256
    </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1257
    <div class="section" title="5.Dictionaries">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1258
     <div class="titlepage">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1259
      <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1260
       <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1261
        <h2 class="title" style="clear: both">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1262
         <a name="id2632038">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1263
         </a>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1264
         5.Dictionaries
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1265
        </h2>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1266
       </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1267
      </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1268
     </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1269
     <p id="ch4strings_dicts_25">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1270
      A dictionary in general, are designed to be able to look up meanings of words.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1271
Similarly, the Python dictionaries are also designed to look up for a specific
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1272
key and retrieve the corresponding value. Dictionaries are data structures that
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1273
provide key-value mappings. Dictionaries are similar to lists except that instead
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1274
of the values having integer indexes, dictionaries have keys or strings as indexes.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1275
Let us look at an example of how to define dictionaries.
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1276
     </p>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1277
     <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1278
      &gt;&gt;&gt; dct = { 'Sachin': 'Tendulkar', 'Rahul': 'Dravid', 'Anil': 'Kumble'}
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1279
     </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1280
     <p id="ch4strings_dicts_26">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1281
      The dictionary consists of pairs of strings, which are called
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1282
      <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1283
       <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1284
        keys
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1285
       </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1286
      </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1287
      and their
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1288
corresponding
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1289
      <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1290
       <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1291
        values
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1292
       </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1293
      </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1294
      separated by
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1295
      <span class="emphasis">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1296
       <em>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1297
        :
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1298
       </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1299
      </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1300
      and each of these
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1301
      <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1302
       <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1303
        key-value
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1304
       </em>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1305
      </span>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1306
      pairs are
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1307
comma(',') separated and the entire structure wrapped in a pair curly braces
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1308
      <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1309
       <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1310
        {}
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1311
       </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1312
      </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1313
      .
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1314
     </p>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1315
     <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1316
      Note: The data inside a dictionary is not ordered. The order in which you enter
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1317
the key-value pairs is not the order in which they are stored in the dictionary.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1318
Python has an internal storage mechanism for that which is out of the purview
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1319
of this document.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1320
     </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1321
     <div class="section" title="5.1.dict()">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1322
      <div class="titlepage">
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1323
       <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1324
        <div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1325
         <h3 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1326
          <a name="id2632094">
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1327
          </a>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1328
          5.1.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1329
          <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1330
           <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1331
            dict()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1332
           </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1333
          </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1334
         </h3>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1335
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1336
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1337
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1338
      <p id="ch4strings_dicts_27">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1339
       The
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1340
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1341
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1342
         dict()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1343
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1344
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1345
       function is used to create dictionaries from other mappings or other
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1346
dictionaries. Let us look at an example.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1347
      </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1348
      <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1349
       &gt;&gt;&gt; diction = dict(mat = 133, avg = 52.53)
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1350
      </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1351
      <p id="ch4strings_dicts_28">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1352
       <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1353
        <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1354
         String Formatting with Dictionaries:
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1355
        </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1356
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1357
      </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1358
      <p id="ch4strings_dicts_29">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1359
       String formatting was discussed in the previous section and it was mentioned that
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1360
dictionaries can also be used for formatting more than one value. This section
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1361
focuses on the formatting of strings using dictionaries. String formatting using
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1362
dictionaries is more appealing than doing the same with tuples. Here the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1363
       <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1364
        <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1365
         keyword
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1366
        </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1367
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1368
       can be used as a place holder and the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1369
       <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1370
        <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1371
         value
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1372
        </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1373
       </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1374
       corresponding to it is replaced in
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1375
the formatted string. Let us look at an example.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1376
      </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1377
      <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1378
       &gt;&gt;&gt; player = { 'Name':'Rahul Dravid', 'Matches':133, 'Avg':52.53, '100s':26 }
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1379
&gt;&gt;&gt; strng = '%(Name)s has played %(Matches)d with an average of %(Avg).2f and has %(100s)d hundreds to his name.'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1380
&gt;&gt;&gt; print strng % player
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1381
Rahul Dravid has played 133 with an average of 52.53 and has 26 hundreds to his name.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1382
      </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1383
     </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1384
     <div class="section" title="5.2.Dictionary Methods">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1385
      <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1386
       <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1387
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1388
         <h3 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1389
          <a name="id2632158">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1390
          </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1391
          5.2.Dictionary Methods
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1392
         </h3>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1393
        </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1394
       </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1395
      </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1396
      <div class="section" title="5.2.1.clear()">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1397
       <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1398
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1399
         <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1400
          <h4 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1401
           <a name="id2632167">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1402
           </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1403
           5.2.1.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1404
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1405
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1406
             clear()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1407
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1408
           </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1409
          </h4>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1410
         </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1411
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1412
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1413
       <p id="ch4strings_dicts_2a">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1414
        The
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1415
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1416
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1417
          clear()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1418
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1419
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1420
        method removes all the existing
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1421
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1422
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1423
          key-value
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1424
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1425
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1426
        pairs from a dictionary.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1427
It returns
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1428
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1429
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1430
          None
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1431
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1432
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1433
        or rather does not return anything. It is a method that changes
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1434
the object. It has to be noted here that dictionaries are not immutable. Let us
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1435
look at an example.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1436
       </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1437
       <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1438
        &gt;&gt;&gt; dct
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1439
{'Anil': 'Kumble', 'Sachin': 'Tendulkar', 'Rahul': 'Dravid'}
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1440
&gt;&gt;&gt; dct.clear()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1441
&gt;&gt;&gt; dct
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1442
{}
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1443
       </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1444
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1445
      <div class="section" title="5.2.2.copy()">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1446
       <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1447
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1448
         <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1449
          <h4 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1450
           <a name="id2632202">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1451
           </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1452
           5.2.2.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1453
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1454
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1455
             copy()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1456
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1457
           </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1458
          </h4>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1459
         </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1460
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1461
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1462
       <p id="ch4strings_dicts_2b">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1463
        The
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1464
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1465
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1466
          copy()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1467
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1468
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1469
        returns a copy of a given dictionary. Let us look at an example.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1470
       </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1471
       <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1472
        &gt;&gt;&gt; dct = {'Anil': 'Kumble', 'Sachin': 'Tendulkar', 'Rahul': 'Dravid'}
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1473
&gt;&gt;&gt; dctcopy = dct.copy()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1474
&gt;&gt;&gt; dctcopy
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1475
{'Anil': 'Kumble', 'Sachin': 'Tendulkar', 'Rahul': 'Dravid'}
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1476
       </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1477
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1478
      <div class="section" title="5.2.3.get()">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1479
       <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1480
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1481
         <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1482
          <h4 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1483
           <a name="id2632233">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1484
           </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1485
           5.2.3.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1486
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1487
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1488
             get()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1489
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1490
           </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1491
          </h4>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1492
         </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1493
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1494
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1495
       <p id="ch4strings_dicts_2c">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1496
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1497
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1498
          get()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1499
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1500
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1501
        returns the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1502
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1503
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1504
          value
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1505
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1506
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1507
        for the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1508
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1509
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1510
          key
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1511
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1512
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1513
        passed as the argument and if the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1514
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1515
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1516
          key
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1517
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1518
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1519
        does not exist in the dictionary, it returns
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1520
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1521
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1522
          None
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1523
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1524
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1525
        . Let us look at an
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1526
example.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1527
       </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1528
       <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1529
        &gt;&gt;&gt; print dctcopy.get('Saurav')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1530
None
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1531
&gt;&gt;&gt; print dctcopy.get('Anil')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1532
Kumble
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1533
       </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1534
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1535
      <div class="section" title="5.2.4.has_key()">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1536
       <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1537
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1538
         <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1539
          <h4 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1540
           <a name="id2632271">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1541
           </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1542
           5.2.4.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1543
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1544
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1545
             has_key()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1546
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1547
           </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1548
          </h4>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1549
         </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1550
        </div>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1551
       </div>
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1552
       <p id="ch4strings_dicts_2d">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1553
        This method returns
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1554
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1555
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1556
          True
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1557
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1558
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1559
        if the given
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1560
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1561
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1562
          key
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1563
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1564
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1565
        is in the dictionary, else it returns
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1566
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1567
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1568
          False
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1569
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1570
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1571
        .
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1572
       </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1573
       <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1574
        &gt;&gt;&gt; dctcopy.has_key('Saurav')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1575
False
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1576
&gt;&gt;&gt; dctcopy.has_key('Sachin')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1577
True
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1578
       </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1579
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1580
      <div class="section" title="5.2.5.pop()">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1581
       <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1582
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1583
         <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1584
          <h4 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1585
           <a name="id2632301">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1586
           </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1587
           5.2.5.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1588
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1589
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1590
             pop()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1591
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1592
           </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1593
          </h4>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1594
         </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1595
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1596
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1597
       <p id="ch4strings_dicts_2e">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1598
        This method is used to retrieve the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1599
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1600
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1601
          value
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1602
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1603
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1604
        of a given
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1605
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1606
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1607
          key
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1608
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1609
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1610
        and subsequently
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1611
remove the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1612
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1613
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1614
          key-value
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1615
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1616
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1617
        pair from the dictionary. Let us look at an example.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1618
       </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1619
       <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1620
        &gt;&gt;&gt; print dctcopy.pop('Sachin')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1621
Tendulkar
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1622
&gt;&gt;&gt; dctcopy
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1623
{'Anil': 'Kumble', 'Rahul': 'Dravid'}
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1624
       </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1625
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1626
      <div class="section" title="5.2.6.popitem()">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1627
       <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1628
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1629
         <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1630
          <h4 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1631
           <a name="id2632335">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1632
           </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1633
           5.2.6.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1634
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1635
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1636
             popitem()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1637
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1638
           </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1639
          </h4>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1640
         </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1641
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1642
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1643
       <p id="ch4strings_dicts_2f">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1644
        This method randomly pops a
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1645
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1646
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1647
          key-value
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1648
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1649
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1650
        pair from a dictionary and returns it.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1651
The
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1652
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1653
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1654
          key-value
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1655
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1656
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1657
        pair returned is removed from the dictionary. Let us look at an
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1658
example.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1659
       </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1660
       <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1661
        &gt;&gt;&gt; print dctcopy.popitem()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1662
('Anil', 'Kumble')
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1663
&gt;&gt;&gt; dctcopy
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1664
{'Rahul': 'Dravid'}
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1665
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1666
Note that the item chosen is completely random since dictionaries are unordered
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1667
as mentioned earlier.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1668
       </pre>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1669
      </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1670
      <div class="section" title="5.2.7.update()">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1671
       <div class="titlepage">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1672
        <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1673
         <div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1674
          <h4 class="title">
27
cb14131583c6 Started on final changes to the build scripts so that we can start with totally automatic builds
amit@thunder
parents: 25
diff changeset
  1675
           <a name="id2632371">
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1676
           </a>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1677
           5.2.7.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1678
           <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1679
            <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1680
             update()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1681
            </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1682
           </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1683
          </h4>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1684
         </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1685
        </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1686
       </div>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1687
       <p id="ch4strings_dicts_30">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1688
        The
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1689
        <span class="strong">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1690
         <strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1691
          update()
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1692
         </strong>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1693
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1694
        method updates the contents of one dictionary with the contents
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1695
of another dictionary. For items with existing
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1696
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1697
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1698
          keys
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1699
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1700
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1701
        their
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1702
        <span class="emphasis">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1703
         <em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1704
          values
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1705
         </em>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1706
        </span>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1707
        are updated,
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1708
and the rest of the items are added. Let us look at an example.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1709
       </p>
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1710
       <pre class="programlisting">
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1711
        &gt;&gt;&gt; dctcopy.update(dct)
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1712
&gt;&gt;&gt; dct
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1713
{'Anil': 'Kumble', 'Sachin': 'Tendulkar', 'Rahul': 'Dravid'}
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1714
&gt;&gt;&gt; dctcopy
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1715
{'Anil': 'Kumble', 'Sachin': 'Tendulkar', 'Rahul': 'Dravid'}
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1716
       </pre>
6
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1717
      </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1718
     </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1719
    </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1720
   </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1721
  </div>
1ce9b33fb6ff sorted the problem related to paths
amit@thunder
parents: 2
diff changeset
  1722
 </body>
0
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
  1723
</html>