SEESenv/web/html/ch2intro.html
author amit@thunder
Tue, 23 Feb 2010 19:43:04 +0530
changeset 25 ed38dd9bdb50
parent 24 10074d1357ff
child 27 cb14131583c6
permissions -rw-r--r--
New build of html solving some of the bugs
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>
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
     2
 <head>
6
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. intro
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>
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    17
 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    18
  <div class="chapter" id="ch2intro">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    19
   <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    20
   </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    21
   <div class="toc">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    22
    <p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    23
     <b>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    24
      Table of Contents
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    25
     </b>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    26
    </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    27
    <dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    28
     <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    29
      <span class="article">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    30
       <a href="#id2809348">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    31
        Basic Python
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    32
       </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    33
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    34
     </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    35
     <dd>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    36
      <dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    37
       <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    38
        <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    39
         <a href="#id2617111">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    40
          1. Introduction
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    41
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    42
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    43
       </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    44
       <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    45
        <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    46
         <a href="#id2860477">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    47
          2. The Python Interpreter
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    48
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    49
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    50
       </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    51
       <dd>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    52
        <dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    53
         <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    54
          <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    55
           <a href="#id2860486">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    56
            2.1. The Interactive Interpreter
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    57
           </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    58
          </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    59
         </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    60
         <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    61
          <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    62
           <a href="#id2860659">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    63
            2.2.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    64
            <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    65
             <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    66
              ipython
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    67
             </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    68
            </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    69
            - An enhanced interactive Python interpreter
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    70
           </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    71
          </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    72
         </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    73
        </dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    74
       </dd>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    75
       <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    76
        <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    77
         <a href="#id2860784">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    78
          3. Editing and running a python file
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    79
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    80
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    81
       </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    82
       <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    83
        <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    84
         <a href="#id2860890">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    85
          4. Basic Datatypes and operators in Python
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    86
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    87
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    88
       </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    89
       <dd>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    90
        <dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    91
         <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    92
          <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    93
           <a href="#id2860925">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    94
            4.1. Numbers
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    95
           </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    96
          </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    97
         </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    98
         <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
    99
          <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   100
           <a href="#id2861055">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   101
            4.2. Variables
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   102
           </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   103
          </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   104
         </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   105
         <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   106
          <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   107
           <a href="#id2861102">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   108
            4.3. Strings
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   109
           </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   110
          </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   111
         </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   112
         <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   113
          <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   114
           <a href="#id2861297">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   115
            4.4. Boolean
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   116
           </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   117
          </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   118
         </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   119
        </dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   120
       </dd>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   121
       <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   122
        <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   123
         <a href="#id2861325">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   124
          5. The
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   125
          <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   126
           <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   127
            while
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   128
           </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   129
          </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   130
          loop
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   131
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   132
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   133
       </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   134
       <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   135
        <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   136
         <a href="#id2861363">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   137
          6. The
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   138
          <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   139
           <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   140
            if
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   141
           </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   142
          </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   143
          conditional
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   144
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   145
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   146
       </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   147
       <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   148
        <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   149
         <a href="#id2861432">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   150
          7.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   151
          <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   152
           <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   153
            raw_input()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   154
           </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   155
          </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   156
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   157
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   158
       </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   159
       <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   160
        <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   161
         <a href="#id2861586">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   162
          8.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   163
          <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   164
           <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   165
            int()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   166
           </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   167
          </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   168
          method
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   169
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   170
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   171
       </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   172
      </dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   173
     </dd>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   174
    </dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   175
   </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   176
   <div class="article" title="Basic Python">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   177
    <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   178
     <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   179
      <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   180
       <h2 class="title">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   181
        <a name="id2809348">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   182
        </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   183
        Basic Python
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   184
       </h2>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   185
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   186
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   187
     <hr />
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   188
    </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   189
    <div class="toc">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   190
     <p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   191
      <b>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   192
       Table of Contents
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   193
      </b>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   194
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   195
     <dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   196
      <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   197
       <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   198
        <a href="#id2617111">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   199
         1. Introduction
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   200
        </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   201
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   202
      </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   203
      <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   204
       <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   205
        <a href="#id2860477">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   206
         2. The Python Interpreter
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   207
        </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   208
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   209
      </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   210
      <dd>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   211
       <dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   212
        <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   213
         <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   214
          <a href="#id2860486">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   215
           2.1. The Interactive Interpreter
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   216
          </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   217
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   218
        </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   219
        <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   220
         <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   221
          <a href="#id2860659">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   222
           2.2.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   223
           <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   224
            <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   225
             ipython
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   226
            </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   227
           </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   228
           - An enhanced interactive Python interpreter
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   229
          </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   230
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   231
        </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   232
       </dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   233
      </dd>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   234
      <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   235
       <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   236
        <a href="#id2860784">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   237
         3. Editing and running a python file
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   238
        </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   239
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   240
      </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   241
      <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   242
       <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   243
        <a href="#id2860890">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   244
         4. Basic Datatypes and operators in Python
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   245
        </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   246
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   247
      </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   248
      <dd>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   249
       <dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   250
        <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   251
         <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   252
          <a href="#id2860925">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   253
           4.1. Numbers
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   254
          </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   255
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   256
        </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   257
        <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   258
         <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   259
          <a href="#id2861055">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   260
           4.2. Variables
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   261
          </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   262
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   263
        </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   264
        <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   265
         <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   266
          <a href="#id2861102">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   267
           4.3. Strings
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   268
          </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   269
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   270
        </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   271
        <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   272
         <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   273
          <a href="#id2861297">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   274
           4.4. Boolean
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   275
          </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   276
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   277
        </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   278
       </dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   279
      </dd>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   280
      <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   281
       <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   282
        <a href="#id2861325">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   283
         5. The
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   284
         <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   285
          <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   286
           while
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   287
          </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   288
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   289
         loop
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   290
        </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   291
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   292
      </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   293
      <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   294
       <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   295
        <a href="#id2861363">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   296
         6. The
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   297
         <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   298
          <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   299
           if
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   300
          </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   301
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   302
         conditional
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   303
        </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   304
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   305
      </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   306
      <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   307
       <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   308
        <a href="#id2861432">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   309
         7.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   310
         <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   311
          <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   312
           raw_input()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   313
          </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   314
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   315
        </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   316
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   317
      </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   318
      <dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   319
       <span class="section">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   320
        <a href="#id2861586">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   321
         8.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   322
         <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   323
          <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   324
           int()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   325
          </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   326
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   327
         method
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   328
        </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   329
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   330
      </dt>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   331
     </dl>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   332
    </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   333
    <p id="ch2intro_1">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   334
     This document is intended to be handed out at the end of the workshop. It has
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   335
been designed for Engineering students who are Python beginners and have basic
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   336
programming skills. The focus is on basic numerics and plotting using Python.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   337
    </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   338
    The system requirements:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   339
    <div class="itemizedlist">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   340
     <ul class="itemizedlist" type="*">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   341
      <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   342
       <p id="ch2intro_2">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   343
        Python - version 2.5.x or newer.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   344
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   345
      </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   346
      <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   347
       <p id="ch2intro_3">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   348
        IPython
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   349
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   350
      </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   351
      <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   352
       <p id="ch2intro_4">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   353
        Text editor - scite, vim, emacs or whatever you are comfortable with.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   354
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   355
      </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   356
     </ul>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   357
    </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   358
    <div class="section" title="1.Introduction">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   359
     <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   360
      <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   361
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   362
        <h2 class="title" style="clear: both">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   363
         <a name="id2617111">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   364
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   365
         1.Introduction
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   366
        </h2>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   367
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   368
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   369
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   370
     <p id="ch2intro_5">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   371
      The Python programming language was created by a dutch named Guido van Rossum.
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   372
The idea of Python was conceived in December 1989. The name Python has nothing
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   373
to do with the reptilian, but its been named after the 70s comedy series
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   374
"Monty Python's Flying Circus", since it happens to be Guido's favourite
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   375
TV series.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   376
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   377
     <p id="ch2intro_6">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   378
      Current stable version of Python is 2.6.x, although Python 3.0 is also the stable
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   379
version, it is not backwards compatible with the previous versions and is hence
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   380
not entirely popular at the moment. This material will focus on the 2.6.x series.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   381
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   382
     <p id="ch2intro_7">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   383
      Python is licensed under the Python Software Foundation License (PSF License)
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   384
which is GPL compatible Free Software license (excepting license version 1.6 and 2.0)
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   385
It is a no strings attached license, which means the source code is free to modify
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   386
and redistribute.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   387
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   388
     <p id="ch2intro_8">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   389
      The Python docs define Python as "Python is an interpreted, object-oriented,
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   390
high-level programming language with dynamic semantics." A more detailed summary
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   391
can be found at
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   392
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   393
     <div class="reference">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   394
      <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   395
       <hr />
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   396
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   397
      http://www.python.org/doc/essays/blurb.html
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   398
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   399
     <p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   400
      . Python is a language that
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
has been designed to help the programmer concentrate on solving the problem at hand
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   402
and not worry about the programming language idiosyncrasies.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   403
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   404
     <p id="ch2intro_9">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   405
      Python is a highly cross platform compatible language on account of it being an
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
interpreted language. It is highly scalable and hence has been adapted to run on
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   407
the Nokia 60 series phones. Python has been designed to be readable and easy to use
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   408
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   409
     <p id="ch2intro_a">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   410
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   411
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   412
        Resources available for reference
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   413
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   414
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   415
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   416
     <div class="itemizedlist">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   417
      <ul class="itemizedlist" type="*">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   418
       <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   419
        <p id="ch2intro_b">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   420
         Web:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   421
        </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   422
        <div class="reference">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   423
         <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   424
          <hr />
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   425
         </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   426
         http://www.python.org
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   427
        </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   428
       </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   429
       <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   430
        <p id="ch2intro_c">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   431
         Doc:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   432
        </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   433
        <div class="reference">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   434
         <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   435
          <hr />
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   436
         </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   437
         http://www.python.org/doc
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   438
        </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   439
       </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   440
       <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   441
        Free Tutorials:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   442
        <div class="itemizedlist">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   443
         <ul class="itemizedlist" type="*">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   444
          <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   445
           <p id="ch2intro_d">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   446
            Official Python Tutorial:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   447
           </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   448
           <div class="reference">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   449
            <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   450
             <hr />
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   451
            </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   452
            http://docs.python.org/tut/tut.html
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   453
           </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   454
          </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   455
          <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   456
           <p id="ch2intro_e">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   457
            Byte of Python:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   458
           </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   459
           <div class="reference">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   460
            <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   461
             <hr />
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   462
            </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   463
            http://www.byteofpython.info/
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   464
           </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   465
          </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   466
          <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   467
           <p id="ch2intro_f">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   468
            Dive into Python:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   469
           </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   470
           <div class="reference">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   471
            <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   472
             <hr />
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   473
            </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   474
            http://diveintopython.org/
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   475
           </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   476
          </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   477
         </ul>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   478
        </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   479
       </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   480
      </ul>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   481
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   482
     <p id="ch2intro_10">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   483
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   484
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   485
        Advantages of Python - Why Python??
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   486
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   487
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   488
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   489
     <div class="itemizedlist">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   490
      <ul class="itemizedlist" type="*">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   491
       <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   492
        <p id="ch2intro_11">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   493
         Python has been designed for readability and ease of use. Its been designed in
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   494
such a fashion that it imposes readability on the programmer. Python does away
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   495
with the braces and the semicolons and instead implements code blocks based on
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   496
indentation, thus enhancing readability.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   497
        </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   498
       </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   499
       <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   500
        <p id="ch2intro_12">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   501
         Python is a high level, interpreted, modular and object oriented language.
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   502
Python performs memory management on its own, thus the programmer need not bother
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   503
about allocating and deallocating memory to variables. Python provides extensibility
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   504
by providing modules which can be easily imported similar to headers in C and
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   505
packages in Java. Python is object oriented and hence provides all the object oriented
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   506
characteristics such as inheritance, encapsulation and polymorphism.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   507
        </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   508
       </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   509
       <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   510
        <p id="ch2intro_13">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   511
         Python offers a highly powerful interactive programming interface in the form
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   512
of the 'Interactive Interpreter' which will be discussed in more detail in the
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   513
following sections.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   514
        </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   515
       </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   516
       <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   517
        <p id="ch2intro_14">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   518
         Python provides a rich standard library and an extensive set of modules. 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
   519
power of Python modules can be seen in this slightly exaggerated cartoon
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   520
        </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   521
        <div class="reference">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   522
         <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   523
          <hr />
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   524
         </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   525
         http://xkcd.com/353/
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   526
        </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   527
       </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   528
       <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   529
        <p id="ch2intro_15">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   530
         Python interfaces well with most other programming languages such as C, C++
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   531
and FORTRAN.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   532
        </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   533
       </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   534
      </ul>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   535
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   536
     <p id="ch2intro_16">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   537
      Although, Python has one setback. Python is not fast as some of the compiled
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   538
languages like C or C++. Yet, the amount of flexibility and power more than make
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   539
up for this setback.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   540
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   541
    </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   542
    <div class="section" title="2.The Python Interpreter">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   543
     <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   544
      <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   545
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   546
        <h2 class="title" style="clear: both">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   547
         <a name="id2860477">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   548
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   549
         2.The Python Interpreter
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   550
        </h2>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   551
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   552
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   553
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   554
     <div class="section" title="2.1.The Interactive Interpreter">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   555
      <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   556
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   557
        <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   558
         <h3 class="title">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   559
          <a name="id2860486">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   560
          </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   561
          2.1.The Interactive Interpreter
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   562
         </h3>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   563
        </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   564
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   565
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   566
      <p id="ch2intro_17">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   567
       Typing
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   568
       <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   569
        <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   570
         python
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   571
        </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   572
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   573
       at the shell prompt on any standard Unix/Gnu-Linux system and
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
hitting the enter key fires up the Python 'Interactive Interpreter'. The Python
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   575
interpreter is one of the most integral features of Python. The prompt obtained
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   576
when the interactive interpreter is similar to what is shown below. The exact
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   577
appearance might differ based on the version of Python being used. The
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   578
       <code class="literal">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   579
        &gt;&gt;&gt;
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   580
       </code>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   581
       thing shown is the python prompt. When something is typed at the prompt and 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
   582
enter key is hit, the python interpreter interprets the command entered and
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   583
performs the appropriate action. All the examples presented in this document are
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   584
to be tried hands on, on the interactive interpreter.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   585
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   586
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   587
       Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49)
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   588
[GCC 4.3.2] on linux2
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   589
Type "help", "copyright", "credits" or "license" for more information.
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   590
&gt;&gt;&gt;
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   591
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   592
      <p id="ch2intro_18">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   593
       Lets try with an example, type
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   594
       <code class="literal">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   595
        print 'Hello, World!'
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   596
       </code>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   597
       at the prompt and hit
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   598
the enter key.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   599
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   600
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   601
       &gt;&gt;&gt; print 'Hello, World!'
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   602
Hello, World!
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   603
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   604
      <p id="ch2intro_19">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   605
       This example was quite straight forward, and thus we have written our first
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   606
line of Python code. Now let us try typing something arbitrary at the prompt.
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   607
For example:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   608
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   609
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   610
       &gt;&gt;&gt; arbit word
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   611
  File "&lt;stdin&gt;", line 1
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   612
    arbit word
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   613
            ^
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   614
SyntaxError: invalid syntax
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   615
&gt;&gt;&gt;
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   616
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   617
      <p id="ch2intro_1a">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   618
       The interpreter gave an error message saying that 'arbit word' was invalid
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
syntax which is valid. The interpreter is an amazing tool when learning to
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   620
program in Python. The interpreter provides a help function that provides the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   621
necessary documentation regarding all Python syntax, constructs, modules and
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   622
objects. Typing
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   623
       <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   624
        <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   625
         help()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   626
        </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   627
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   628
       at the prompt gives the following output:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   629
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   630
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   631
       &gt;&gt;&gt; help()
0
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
   632
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   633
Welcome to Python 2.5!  This is the online help utility.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   634
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   635
If this is your first time using Python, you should definitely check out
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   636
the tutorial on the Internet at http://www.python.org/doc/tut/.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   637
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   638
Enter the name of any module, keyword, or topic to get help on writing
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   639
Python programs and using Python modules.  To quit this help utility and
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   640
return to the interpreter, just type "quit".
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   641
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   642
To get a list of available modules, keywords, or topics, type "modules",
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   643
"keywords", or "topics".  Each module also comes with a one-line summary
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   644
of what it does; to list the modules whose summaries contain a given word
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   645
such as "spam", type "modules spam".
1
672eaaab9204 Added some new html files that failed earlier during change from rst
amit@thunder
parents: 0
diff changeset
   646
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   647
help&gt;
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   648
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   649
      <p id="ch2intro_1b">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   650
       As mentioned in the output, entering the name of any module, keyword or topic
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   651
will provide the documentation and help regarding the same through the online
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   652
help utility. Pressing
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   653
       <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   654
        <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   655
         Ctrl+d
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   656
        </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   657
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   658
       exits the help prompt and returns to the
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   659
python prompt.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   660
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   661
      <p id="ch2intro_1c">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   662
       Let us now try a few examples at the python interpreter.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   663
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   664
      <p id="ch2intro_1d">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   665
       Eg 1:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   666
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   667
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   668
       &gt;&gt;&gt; print 'Hello, python!'
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   669
Hello, python!
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   670
&gt;&gt;&gt;
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   671
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   672
      <p id="ch2intro_1e">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   673
       Eg 2:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   674
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   675
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   676
       &gt;&gt;&gt; print 4321*567890
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   677
2453852690
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   678
&gt;&gt;&gt;
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   679
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   680
      <p id="ch2intro_1f">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   681
       Eg 3:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   682
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   683
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   684
       &gt;&gt;&gt; 4321*567890
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   685
2453852690L
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   686
&gt;&gt;&gt;
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   687
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   688
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   689
       Note: Notice the 'L' at the end of the output. The 'L' signifies that 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
   690
output of the operation is of type *long*. It was absent in the previous
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   691
example because we used the print statement. This is because *print* formats
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   692
the output before displaying.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   693
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   694
      <p id="ch2intro_20">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   695
       Eg 4:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   696
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   697
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   698
       &gt;&gt;&gt; big = 12345678901234567890 ** 3
24
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; print big
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   700
1881676372353657772490265749424677022198701224860897069000
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   701
&gt;&gt;&gt;
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   702
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   703
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   704
       This example is to show that unlike in C or C++ there is no limit on the
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   705
value of an integer.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   706
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   707
      <p id="ch2intro_21">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   708
       Try this on the interactive interpreter:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   709
       <code class="literal">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   710
        import this
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   711
       </code>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   712
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   713
      <p id="ch2intro_22">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   714
       <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   715
        <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   716
         Hint: The output gives an idea of Power of Python
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   717
        </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   718
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   719
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   720
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   721
     <div class="section" title="2.2.ipython - An enhanced interactive Python interpreter">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   722
      <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   723
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   724
        <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   725
         <h3 class="title">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   726
          <a name="id2860659">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   727
          </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   728
          2.2.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   729
          <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   730
           <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   731
            ipython
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   732
           </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   733
          </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   734
          - An enhanced interactive Python interpreter
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   735
         </h3>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   736
        </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   737
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   738
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   739
      <p id="ch2intro_23">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   740
       The power and the importance of the interactive interpreter was the highlight
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   741
of the previous section. This section provides insight into the enhanced
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   742
interpreter with more advanced set of features called
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   743
       <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   744
        <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   745
         ipython
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   746
        </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   747
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   748
       . Entering
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   749
       <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   750
        <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   751
         ipython
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   752
        </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   753
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   754
       at the shell prompt fires up the interactive interpreter.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   755
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   756
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   757
       $ ipython
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   758
Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49)
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   759
Type "copyright", "credits" or "license" for more information.
1
672eaaab9204 Added some new html files that failed earlier during change from rst
amit@thunder
parents: 0
diff changeset
   760
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   761
IPython 0.8.4 -- An enhanced Interactive Python.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   762
?         -&gt; Introduction and overview of IPython's features.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   763
%quickref -&gt; Quick reference.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   764
help      -&gt; Python's own help system.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   765
object?   -&gt; Details about 'object'. ?object also works, ?? prints more.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   766
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   767
In [1]:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   768
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   769
      <p id="ch2intro_24">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   770
       This is the output obtained upon firing ipython. The exact appearance may
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   771
change based on the Python version installed. The following are some of the
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   772
various features provided by
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   773
       <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   774
        <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   775
         ipython
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   776
        </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   777
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   778
       :
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   779
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   780
      <p id="ch2intro_25">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   781
       Suggestions - ipython provides suggestions of the possible methods and
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   782
operations available for the given python object.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   783
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   784
      <p id="ch2intro_26">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   785
       Eg 5:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   786
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   787
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   788
       In [4]: a = 6
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   789
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   790
In [5]: a.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   791
a.__abs__           a.__divmod__        a.__index__         a.__neg__          a.__rand__          a.__rmod__          a.__rxor__
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   792
a.__add__           a.__doc__           a.__init__          a.__new__          a.__rdiv__          a.__rmul__          a.__setattr__
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   793
a.__and__           a.__float__         a.__int__           a.__nonzero__      a.__rdivmod__       a.__ror__           a.__str__
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   794
a.__class__         a.__floordiv__      a.__invert__        a.__oct__          a.__reduce__        a.__rpow__          a.__sub__
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   795
a.__cmp__           a.__getattribute__  a.__long__          a.__or__           a.__reduce_ex__     a.__rrshift__       a.__truediv__
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   796
a.__coerce__        a.__getnewargs__    a.__lshift__        a.__pos__          a.__repr__          a.__rshift__        a.__xor__
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   797
a.__delattr__       a.__hash__          a.__mod__           a.__pow__          a.__rfloordiv__     a.__rsub__
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   798
a.__div__           a.__hex__           a.__mul__           a.__radd__         a.__rlshift__       a.__rtruediv__
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   799
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   800
      <p id="ch2intro_27">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   801
       In this example, we initialized 'a' (a variable - a concept that will be
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   802
discussed in the subsequent sections.) to 6. In the next line when the
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   803
       <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   804
        <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   805
         tab
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   806
        </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   807
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   808
       key
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   809
is pressed after typing '
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   810
       <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   811
        <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   812
         a.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   813
        </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   814
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   815
       ' ipython displays the set of all possible methods
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   816
that are applicable on the object 'a' (an integer in this context). Ipython
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   817
provides many such datatype specific features which will be presented in the
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   818
further sections as and when the datatypes are introduced.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   819
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   820
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   821
    </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   822
    <div class="section" title="3.Editing and running a python file">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   823
     <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   824
      <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   825
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   826
        <h2 class="title" style="clear: both">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   827
         <a name="id2860784">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   828
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   829
         3.Editing and running a python file
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   830
        </h2>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   831
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   832
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   833
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   834
     <p id="ch2intro_28">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   835
      The previous sections focused on the use of the interpreter to run python code.
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   836
While the interpeter is an excellent tool to test simple solutions and
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   837
experiment with small code snippets, its main disadvantage is that everything
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   838
written in the interpreter is lost once its quit. Most of the times a program is
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   839
used by people other than the author. So the programs have to be available in
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   840
some form suitable for distribution, and hence they are written in files. This
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   841
section will focus on editing and running python files. Start by opening a text
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   842
editor ( it is recommended you choose one from the list at the top of this page ).
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   843
In the editor type down python code and save the file with an extension
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   844
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   845
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   846
        .py
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   847
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   848
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   849
      (python files have an extension of .py). Once done with the editing, save the
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   850
file and exit the editor.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   851
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   852
     <p id="ch2intro_29">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   853
      Let us look at a simple example of calculating the gcd of 2 numbers using Python:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   854
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   855
     <p id="ch2intro_2a">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   856
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   857
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   858
        Creating the first python script(file)
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   859
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   860
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   861
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   862
     <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   863
      $ emacs gcd.py
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   864
  def gcd(x,y):
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   865
    if x % y == 0:
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   866
      return y
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   867
    return gcd(y, x%y)
1
672eaaab9204 Added some new html files that failed earlier during change from rst
amit@thunder
parents: 0
diff changeset
   868
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   869
  print gcd(72, 92)
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   870
     </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   871
     <p id="ch2intro_2b">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   872
      To run the script, open the shell prompt, navigate to the directory that
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   873
contains the python file and run
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   874
      <code class="literal">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   875
       python &lt;filename.py&gt;
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   876
      </code>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   877
      at the prompt ( in this
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   878
case filename is gcd.py )
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   879
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   880
     <p id="ch2intro_2c">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   881
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   882
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   883
        Running the python script
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   884
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   885
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   886
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   887
     <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   888
      $ python gcd.py
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   889
4
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   890
$
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   891
     </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   892
     <p id="ch2intro_2d">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   893
      Another method to run a python script would be to include the line
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   894
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   895
     <p id="ch2intro_2e">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   896
      <code class="literal">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   897
       #! /usr/bin/python
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   898
      </code>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   899
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   900
     <p id="ch2intro_2f">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   901
      at the beginning of the python file and then make the file executable by
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   902
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   903
     <p id="ch2intro_30">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   904
      $ chmod a+x
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   905
      <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   906
       <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   907
        filename.py
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   908
       </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   909
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   910
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   911
     <p id="ch2intro_31">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   912
      Once this is done, the script can be run as a standalone program as follows:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   913
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   914
     <p id="ch2intro_32">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   915
      $ ./
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   916
      <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   917
       <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   918
        filename.py
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   919
       </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   920
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   921
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   922
    </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   923
    <div class="section" title="4.Basic Datatypes and operators in Python">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   924
     <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   925
      <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   926
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   927
        <h2 class="title" style="clear: both">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   928
         <a name="id2860890">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   929
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   930
         4.Basic Datatypes and operators in Python
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   931
        </h2>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   932
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   933
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   934
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   935
     <p id="ch2intro_33">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   936
      Python provides the following set of basic datatypes.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   937
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   938
     <div class="itemizedlist">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   939
      <ul class="itemizedlist" type="*">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   940
       <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   941
        <p id="ch2intro_34">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   942
         Numbers: int, float, long, complex
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   943
        </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   944
       </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   945
       <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   946
        <p id="ch2intro_35">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   947
         Strings
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   948
        </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   949
       </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   950
       <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   951
        <p id="ch2intro_36">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   952
         Boolean
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   953
        </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   954
       </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   955
      </ul>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   956
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   957
     <div class="section" title="4.1.Numbers">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   958
      <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   959
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   960
        <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   961
         <h3 class="title">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   962
          <a name="id2860925">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   963
          </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   964
          4.1.Numbers
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   965
         </h3>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   966
        </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   967
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   968
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   969
      <p id="ch2intro_37">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   970
       Numbers were introduced in the examples presented in the interactive interpreter
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   971
section. Numbers include types as mentioned earlier viz., int (integers), float
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   972
(floating point numbers), long (large integers), complex (complex numbers with
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   973
real and imaginary parts). Python is not a strongly typed language, which means
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   974
the type of a variable need not mentioned during its initialization. Let us look
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   975
at a few examples.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   976
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   977
      <p id="ch2intro_38">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   978
       Eg 6:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   979
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   980
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   981
       &gt;&gt;&gt; a = 1 #here a is an integer variable
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   982
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   983
      <p id="ch2intro_39">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   984
       Eg 7:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   985
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   986
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   987
       &gt;&gt;&gt; lng = 122333444455555666666777777788888888999999999 #here lng is a variable of type long
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   988
&gt;&gt;&gt; lng
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   989
122333444455555666666777777788888888999999999L #notice the trailing 'L'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   990
&gt;&gt;&gt; print lng
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   991
122333444455555666666777777788888888999999999 #notice the absence of the trailing 'L'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   992
&gt;&gt;&gt; lng+1
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   993
122333444455555666666777777788888889000000000L
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   994
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   995
      <p id="ch2intro_3a">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
   996
       Long numbers are the same as integers in almost all aspects. They can be used in
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   997
operations just like integers and along with integers without any distinction.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   998
The only distinction comes during type checking (which is not a healthy practice).
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
   999
Long numbers are tucked with a trailing 'L' just to signify that they are long.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1000
Notice that in the example just lng at the prompt displays the value of the variable
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1001
with the 'L' whereas
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1002
       <code class="literal">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1003
        print lng
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1004
       </code>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1005
       displays without the 'L'. This is because print
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1006
formats the output before printing. Also in the example, notice that adding an
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1007
integer to a long does not give any errors and the result is as expected. So for
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1008
all practical purposes longs can be treated as ints.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1009
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1010
      <p id="ch2intro_3b">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1011
       Eg 8:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1012
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1013
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1014
       &gt;&gt;&gt; fl = 3.14159 #fl is a float variable
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1015
&gt;&gt;&gt; e = 1.234e-4 #e is also a float variable, specified in the exponential form
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1016
&gt;&gt;&gt; a = 1
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1017
&gt;&gt;&gt; b = 2
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1018
&gt;&gt;&gt; a/b #integer division
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1019
0
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1020
&gt;&gt;&gt; a/fl #floating point division
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1021
0.31831015504887655
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1022
&gt;&gt;&gt; e/fl
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1023
3.9279473133031364e-05
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1024
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1025
      <p id="ch2intro_3c">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1026
       Floating point numbers, simply called floats are real numbers with a decimal point.
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1027
The example above shows the initialization of a float variable. Shown also 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
  1028
example is the difference between integer division and floating point division.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1029
'a' and 'b' here are integer variables and hence the division gives 0 as the quotient.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1030
When either of the operands is a float, the operation is a floating point division,
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1031
and the result is also a float as illustrated.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1032
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1033
      <p id="ch2intro_3d">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1034
       Eg 9:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1035
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1036
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1037
       &gt;&gt;&gt; cplx = 3 + 4j #cplx is a complex variable
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
&gt;&gt;&gt; cplx
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1039
(3+4j)
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1040
&gt;&gt;&gt; print cplx.real #prints the real part of the complex number
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1041
3.0
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1042
&gt;&gt;&gt; print cplx.imag #prints the imaginary part of the complex number
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1043
4.0
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1044
&gt;&gt;&gt; print cplx*fl  #multiplies the real and imag parts of the complex number with the multiplier
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1045
(9.42477+12.56636j)
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1046
&gt;&gt;&gt; abs(cplx) #returns the absolute value of the complex number
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1047
5.0
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1048
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1049
      <p id="ch2intro_3e">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1050
       Python provides a datatype for complex numbers. Complex numbers are initialized
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1051
as shown in the example above. The
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1052
       <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1053
        <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1054
         real
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1055
        </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1056
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1057
       and
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1058
       <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1059
        <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1060
         imag
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1061
        </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1062
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1063
       operators return the real and
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1064
imaginary parts of the complex number as shown. The
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1065
       <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1066
        <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1067
         abs()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1068
        </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1069
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1070
       returns the absolute
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1071
value of the complex number.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1072
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1073
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1074
     <div class="section" title="4.2.Variables">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1075
      <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1076
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1077
        <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1078
         <h3 class="title">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1079
          <a name="id2861055">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1080
          </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1081
          4.2.Variables
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1082
         </h3>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1083
        </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1084
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1085
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1086
      <p id="ch2intro_3f">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1087
       Variables are just names that represent a value. Variables have already been
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1088
introduced in the various examples from the previous sections. Certain rules about
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1089
using variables:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1090
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1091
      <div class="itemizedlist">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1092
       <ul class="itemizedlist" type="*">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1093
        <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1094
         <p id="ch2intro_40">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1095
          Variables have to be initialized or assigned a value before being used.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1096
         </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1097
        </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1098
        <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1099
         <p id="ch2intro_41">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1100
          Variable names can consist of letters, digits and underscores(_).
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1101
         </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1102
        </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1103
        <li class="listitem" style="list-style-type: *">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1104
         <p id="ch2intro_42">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1105
          Variable names cannot begin with digits, but can contain digits in them.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1106
         </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1107
        </li>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1108
       </ul>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1109
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1110
      <p id="ch2intro_43">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1111
       In reference to the previous section examples, 'a', 'b', 'lng', 'fl', 'e' and 'cplx'
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1112
are all variables of various datatypes.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1113
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1114
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1115
       Note: Python is not a strongly typed language and hence an integer variable can at a
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1116
later stage be used as a float variable as well.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1117
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1118
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1119
     <div class="section" title="4.3.Strings">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1120
      <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1121
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1122
        <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1123
         <h3 class="title">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1124
          <a name="id2861102">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1125
          </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1126
          4.3.Strings
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1127
         </h3>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1128
        </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1129
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1130
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1131
      <p id="ch2intro_44">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1132
       Strings are one of the essential data structures of any programming language.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1133
The
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1134
       <code class="literal">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1135
        print "Hello, World!"
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1136
       </code>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1137
       program was introduced in the earlier section, and
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1138
the
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1139
       <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1140
        <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1141
         "Hello, World!"
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1142
        </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1143
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1144
       in the print statement is a string. A string is basically
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1145
a set of characters. Strings can be represented in various ways shown below:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1146
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1147
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1148
       s = 'this is a string'              # a string variable can be represented using single quotes
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1149
s = 'This one has "quotes" inside!' # The string can have quotes inside it as shown
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1150
s = "I have 'single-quotes' inside!"
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1151
l = "A string spanning many lines 
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1152
one more line 
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1153
yet another"                        # a string can span more than a single line.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1154
t = """A triple quoted string does  # another way of representing multiline strings.
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1155
not need to be escaped at the end and
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1156
"can have nested quotes" etc."""
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1157
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1158
      <p id="ch2intro_45">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1159
       Try the following on the interpreter:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1160
       <code class="literal">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1161
        s = 'this is a string with 'quotes' of similar kind'
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1162
       </code>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1163
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1164
      <p id="ch2intro_46">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1165
       <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1166
        <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1167
         Exercise: How to use single quotes within single quotes in a string as shown
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1168
in the above example without getting an error?
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1169
        </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1170
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1171
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1172
      <div class="section" title="4.3.1.String operations">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1173
       <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1174
        <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1175
         <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1176
          <h4 class="title">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1177
           <a name="id2861154">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1178
           </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1179
           4.3.1.String operations
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1180
          </h4>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1181
         </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1182
        </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1183
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1184
       <p id="ch2intro_47">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1185
        A few basic string operations are presented here.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1186
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1187
       <p id="ch2intro_48">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1188
        <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1189
         <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1190
          String concatenation
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1191
         </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1192
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1193
        String concatenation is done by simple addition of two strings.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1194
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1195
       <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1196
        &gt;&gt;&gt; x = 'Hello'
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1197
&gt;&gt;&gt; y = ' Python'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1198
&gt;&gt;&gt; print x+y
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1199
Hello Python
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1200
       </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1201
       <p id="ch2intro_49">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1202
        <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1203
         <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1204
          Try this yourself:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1205
         </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1206
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1207
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1208
       <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1209
        &gt;&gt;&gt; somenum = 13
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1210
&gt;&gt;&gt; print x+somenum
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1211
       </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1212
       <p id="ch2intro_4a">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1213
        The problem with the above example is that here a string variable and an integer
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1214
variable are trying to be concantenated. To obtain the desired result from the
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1215
above example the str(), repr() and the `` can be used.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1216
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1217
       <p id="ch2intro_4b">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1218
        <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1219
         <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1220
          str()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1221
         </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1222
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1223
        simply converts a value to a string in a reasonable form.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1224
        <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1225
         <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1226
          repr()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1227
         </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1228
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1229
        creates a string that is a representation of the value.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1230
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1231
       <p id="ch2intro_4c">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1232
        The difference can be seen in the example shown below:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1233
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1234
       <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1235
        &gt;&gt;&gt; str(1000000000000000000000000000000000000000000000000L)
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1236
'1000000000000000000000000000000000000000000000000'
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1237
&gt;&gt;&gt; repr(1000000000000000000000000000000000000000000000000L)
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1238
'1000000000000000000000000000000000000000000000000L'
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1239
       </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1240
       <p id="ch2intro_4d">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1241
        It can be observed that the 'L' in the long value shown was omitted by str(),
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1242
whereas repr() converted that into a string too. An alternative way of using
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1243
repr(value) is
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1244
        <code class="literal">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1245
         `value`
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1246
        </code>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1247
        .
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1248
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1249
       <p id="ch2intro_4e">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1250
        A few more examples:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1251
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1252
       <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1253
        &gt;&gt;&gt; x = "Let's go  nto Pycon"
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1254
&gt;&gt;&gt; print x
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1255
Let's go
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1256
to Pycon
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1257
       </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1258
       <p id="ch2intro_4f">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1259
        In the above example, notice that the 'n'(newline) character is formatted and
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1260
the string is printed on two lines. The strings discussed until now were normal
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1261
strings. Other than these there are two other types of strings namely, raw strings
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1262
and unicode strings.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1263
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1264
       <p id="ch2intro_50">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1265
        <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1266
         <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1267
          Raw strings
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1268
         </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1269
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1270
        are strings which are unformatted, that is the backslashes() are
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1271
not parsed and are left as it is in the string. Raw strings are represented with
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1272
an 'r' at the start of a string.
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1273
Let us look at an example
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1274
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1275
       <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1276
        &gt;&gt;&gt; x = r"Let's go  nto Pycon"
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
&gt;&gt;&gt; print x
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1278
Let's go  nto Pycon
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1279
       </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1280
       <p id="ch2intro_51">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1281
        Note: The 'n' is not being parsed into a new line and is left as it is.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1282
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1283
       <p id="ch2intro_52">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1284
        <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1285
         <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1286
          Try this yourself:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1287
         </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1288
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1289
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1290
       <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1291
        &gt;&gt;&gt; x = r"Let's go to Pycon "
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1292
       </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1293
       <p id="ch2intro_53">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1294
        <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1295
         <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1296
          Unicode strings
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1297
         </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1298
        </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1299
        are strings where the characters are Unicode characters as
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1300
opposed to ASCII characters. Unicode strings are represented with a 'u' at the
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1301
start of the string.
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1302
Let us look at an example:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1303
       </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1304
       <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1305
        &gt;&gt;&gt; x = u"Let's go to Pycon!"
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
&gt;&gt;&gt; print x
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1307
Let's go to Pycon!
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1308
       </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1309
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1310
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1311
     <div class="section" title="4.4.Boolean">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1312
      <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1313
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1314
        <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1315
         <h3 class="title">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1316
          <a name="id2861297">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1317
          </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1318
          4.4.Boolean
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1319
         </h3>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1320
        </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1321
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1322
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1323
      <p id="ch2intro_54">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1324
       Python also provides special Boolean datatype. A boolean variable can assume a
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1325
value of either
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1326
       <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1327
        <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1328
         True
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1329
        </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1330
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1331
       or
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1332
       <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1333
        <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1334
         False
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1335
        </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1336
       </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1337
       (Note the capitalizations).
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1338
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1339
      <p id="ch2intro_55">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1340
       Let us look at examples:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1341
      </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1342
      <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1343
       &gt;&gt;&gt; t = True
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1344
&gt;&gt;&gt; f = not t
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1345
&gt;&gt;&gt; print f
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1346
False
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1347
&gt;&gt;&gt; f or t
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1348
True
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; f and t
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1350
False
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1351
      </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1352
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1353
    </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1354
    <div class="section" title="5.The while loop">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1355
     <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1356
      <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1357
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1358
        <h2 class="title" style="clear: both">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1359
         <a name="id2861325">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1360
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1361
         5.The
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1362
         <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1363
          <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1364
           while
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1365
          </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1366
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1367
         loop
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1368
        </h2>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1369
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1370
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1371
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1372
     <p id="ch2intro_56">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1373
      The Python
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1374
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1375
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1376
        while
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1377
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1378
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1379
      loop is similar to the C/C++ while loop. The syntax is as
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1380
follows:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1381
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1382
     <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1383
      statement 0
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1384
while condition:
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1385
  statement 1 #while block
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1386
  statement 2 #while block
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1387
statement 3 #outside the while block.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1388
     </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1389
     <p id="ch2intro_57">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1390
      Let us look at an example:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1391
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1392
     <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1393
      &gt;&gt;&gt; x = 1
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1394
&gt;&gt;&gt; while x &lt;= 5:
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1395
...   print x
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1396
...   x += 1
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1397
...
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1398
1
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1399
2
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1400
3
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1401
4
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1402
5
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1403
     </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1404
    </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1405
    <div class="section" title="6.The if conditional">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1406
     <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1407
      <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1408
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1409
        <h2 class="title" style="clear: both">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1410
         <a name="id2861363">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1411
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1412
         6.The
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1413
         <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1414
          <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1415
           if
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1416
          </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1417
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1418
         conditional
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1419
        </h2>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1420
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1421
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1422
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1423
     <p id="ch2intro_58">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1424
      The Python
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1425
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1426
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1427
        if
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1428
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1429
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1430
      block provides the conditional execution of statements.
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1431
If the condition evaluates as true the block of statements defined under the if
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1432
block are executed.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1433
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1434
     <p id="ch2intro_59">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1435
      If the first block is not executed on account of the condition not being satisfied,
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1436
the set of statements in the
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1437
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1438
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1439
        else
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1440
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1441
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1442
      block are executed.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1443
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1444
     <p id="ch2intro_5a">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1445
      The
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1446
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1447
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1448
        elif
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1449
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1450
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1451
      block provides the functionality of evaluation of multiple conditions
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1452
as shown in the example.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1453
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1454
     <p id="ch2intro_5b">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1455
      The syntax is as follows:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1456
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1457
     <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1458
      if condition :
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1459
    statement_1
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1460
    statement_2
1
672eaaab9204 Added some new html files that failed earlier during change from rst
amit@thunder
parents: 0
diff changeset
  1461
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1462
elif condition:
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1463
    statement_3
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1464
    statement_4
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1465
else:
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1466
    statement_5
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1467
    statement_6
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1468
     </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1469
     <p id="ch2intro_5c">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1470
      Let us look at an example:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1471
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1472
     <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1473
      &gt;&gt;&gt; n = raw_input("Input a number:")
24
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; if n &lt; 0:
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1475
      print n," is negative"
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1476
      elif n &gt; 0:
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1477
      print n," is positive"
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1478
      else:
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1479
      print n, " is 0"
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1480
     </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1481
    </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1482
    <div class="section" title="7.raw_input()">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1483
     <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1484
      <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1485
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1486
        <h2 class="title" style="clear: both">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1487
         <a name="id2861432">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1488
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1489
         7.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1490
         <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1491
          <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1492
           raw_input()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1493
          </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1494
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1495
        </h2>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1496
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1497
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1498
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1499
     <p id="ch2intro_5d">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1500
      In the previous example we saw the call to the raw_input() subroutine.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1501
The
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1502
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1503
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1504
        raw_input()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1505
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1506
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1507
      method is used to take user inputs through the console.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1508
Unlike
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1509
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1510
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1511
        input()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1512
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1513
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1514
      which assumes the data entered by the user as a standard python
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1515
expression,
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1516
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1517
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1518
        raw_input()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1519
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1520
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1521
      treats all the input data as raw data and converts
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1522
everything into a string. To illustrate this let us look at an example.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1523
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1524
     <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1525
      &gt;&gt;&gt; input("Enter a number thats a palindrome:")
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1526
Enter a number thats a palindrome:121
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1527
121
0
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
  1528
24
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; input("Enter your name:")
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1530
Enter your 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
  1531
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
  1532
  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
  1533
  File "&lt;string&gt;", line 1, in &lt;module&gt;
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1534
NameError: name 'PythonFreak' is not defined
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1535
     </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1536
     <p id="ch2intro_5e">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1537
      As shown above the
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1538
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1539
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1540
        input()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1541
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1542
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1543
      assumes that the data entered is a valid Python
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1544
expression. In the first call it prompts for an integer input and when entered
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1545
it accepts the integer as an integer, whereas in the second call, when the string
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1546
is entered without the quotes,
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1547
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1548
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1549
        input()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1550
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1551
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1552
      assumes that the entered data is a valid
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1553
Python expression and hence it raises and exception saying PythonFreak is not
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1554
defined.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1555
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1556
     <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1557
      &gt;&gt;&gt; input("Enter your name:")
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1558
Enter your 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
  1559
'PythonFreak'
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1560
&gt;&gt;&gt;
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1561
     </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1562
     <p id="ch2intro_5f">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1563
      Here the name is accepted because its entered as a string (within quotes). But
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1564
its unreasonable to go on using quotes each time a string is entered. Hence the
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1565
alternative is to use
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1566
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1567
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1568
        raw_input()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1569
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1570
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1571
      .
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1572
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1573
     <p id="ch2intro_60">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1574
      Let us now look at how
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1575
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1576
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1577
        raw_input()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1578
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1579
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1580
      operates with an example.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1581
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1582
     <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1583
      &gt;&gt;&gt; raw_input("Enter your name:")
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1584
Enter your name:PythonFreak
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1585
'PythonFreak'
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1586
     </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1587
     <p id="ch2intro_61">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1588
      Observe that the
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1589
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1590
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1591
        raw_input()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1592
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1593
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1594
      is converting it into a string all by itself.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1595
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1596
     <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1597
      &gt;&gt;&gt; pal = raw_input("Enter a number thats a palindrome:")
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1598
Enter a number thats a palindrome:121
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1599
'121'
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1600
     </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1601
     <p id="ch2intro_62">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1602
      Observe that
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1603
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1604
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1605
        raw_input()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1606
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1607
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1608
      is converting the integer 121 also to a string as
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1609
'121'. Let us look at another example:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1610
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1611
     <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1612
      &gt;&gt;&gt; pal = raw_input("Enter a number thats a palindrome:")
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1613
Enter a number thats a palindrome:121
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1614
&gt;&gt;&gt; pal + 2
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1615
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
  1616
  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
  1617
TypeError: cannot concatenate 'str' and 'int' objects
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1618
&gt;&gt;&gt; pal
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1619
'121'
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1620
     </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1621
     <p id="ch2intro_63">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1622
      Observe here that the variable
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1623
      <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1624
       <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1625
        pal
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1626
       </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1627
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1628
      is a string and hence integer operations
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1629
cannot be performed on it. Hence the exception is raised.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1630
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1631
    </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1632
    <div class="section" title="8.int() method">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1633
     <div class="titlepage">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1634
      <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1635
       <div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1636
        <h2 class="title" style="clear: both">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1637
         <a name="id2861586">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1638
         </a>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1639
         8.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1640
         <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1641
          <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1642
           int()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1643
          </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1644
         </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1645
         method
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1646
        </h2>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1647
       </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1648
      </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1649
     </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1650
     <p id="ch2intro_64">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1651
      Generally for computing purposes, the data used is not strings or raw data but
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1652
on integers, floats and similar mathematical data structures. The data obtained
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1653
from
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1654
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1655
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1656
        raw_input()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1657
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1658
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1659
      is raw data in the form of strings. In order to obtain integers
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1660
from strings we use the method
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1661
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1662
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1663
        int()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1664
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1665
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1666
      .
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1667
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1668
     <p id="ch2intro_65">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1669
      Let us look at an example.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1670
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1671
     <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1672
      &gt;&gt;&gt; intpal = int(pal)
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1673
&gt;&gt;&gt; intpal
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1674
121
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1675
     </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1676
     <p id="ch2intro_66">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1677
      In the previous example it was observed that
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1678
      <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1679
       <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1680
        pal
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1681
       </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1682
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1683
      was a string variable. Here
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1684
using the
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1685
      <span class="strong">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1686
       <strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1687
        int()
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1688
       </strong>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1689
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1690
      method the string
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1691
      <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1692
       <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1693
        pal
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1694
       </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1695
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1696
      was converted to an integer variable.
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1697
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1698
     <p id="ch2intro_67">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1699
      <span class="emphasis">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1700
       <em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1701
        Try This Yourself:
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1702
       </em>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1703
      </span>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1704
     </p>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1705
     <pre class="programlisting">
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1706
      &gt;&gt;&gt; stringvar = raw_input("Enter a name:")
24
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1707
Enter a name:Guido Van Rossum
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1708
&gt;&gt;&gt; stringvar
10074d1357ff Some changes after the horrible problem of writing the same ch9 on all the html pages
amit@thunder
parents: 16
diff changeset
  1709
'Guido Van Rossum'
25
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1710
&gt;&gt;&gt; numvar = int(stringvar)
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1711
     </pre>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1712
    </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1713
   </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1714
  </div>
ed38dd9bdb50 New build of html solving some of the bugs
amit@thunder
parents: 24
diff changeset
  1715
 </body>
0
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
  1716
</html>