basic-python.txt
author amit@shrike.aero.iitb.ac.in
Tue, 20 Apr 2010 13:39:41 +0530
changeset 93 bdee3ead116d
parent 78 099a2cc6c7d2
child 98 8e02b76cf068
permissions -rw-r--r--
Some more additions to basic python ended discussion on string started operators
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
73
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
     1
*Script
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
     2
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
     3
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
     4
*Hello and welcome to this tutorial on Basic Python using Python.
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
     5
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
     6
This tutorial formally introduces Python as a language . Through this tutorial we will be able to understand Basic Data types like number , Boolean and strings .Some basic operators , simple input/output and basic conditional flow . 
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
     7
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
     8
In numbers Python supports three kinds of data types ,
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
     9
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    10
floats,integers and complex numbers
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    11
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    12
An integer can be defined as follows :
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    13
a=13
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    14
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    15
This make a an integer variable with value 13 .
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    16
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    17
You can also type 9 around 20 times 
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    18
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    19
a=99999999999999999999999 . as you can see Python does not have a limit on how long an integer has to be . Isn't that great . 
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    20
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    21
Now will try a float.
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    22
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    23
let's type 
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    24
p=3.141592  if you type out p now you will notice that it is not absolutely equal to p you typed in . The reason for that is how a computer saves decimal values . 
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    25
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    26
Apart from integer and float, Python has an in-built support for complex numbers. Now we try to assign a complex value to a variable .
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    27
Type:
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    28
c = 3+4j
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    29
As you can see ,the notation for complex numbers is similar to the one used in electric engineering. 
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    30
We will now try some operations on complex numbers . First we will try to get the absolute value of the complex number . For this we will use the abs built in function . For this do :
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    31
abs in parenthesis c . 
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    32
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    33
Do get the imaginary part of c you can do :
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    34
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    35
c.imag
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    36
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    37
and similarly for real part do :
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    38
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    39
c.real
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    40
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    41
Python also has Boolean as a built-in type .
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    42
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    43
Try it out just type ..
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    44
 t=True , note that T in true is capitalized .    
78
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    45
  
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    46
You can apply different Boolean operations on t now for example :
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    47
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    48
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    49
f=not t , this saves the value of not t that is False in f. 
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    50
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    51
We can apply other operators like or and and ,
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    52
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    53
f or t gives us the value True while 
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    54
f and t gives us the value false.
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    55
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    56
You can use parenthesis for precedence , 
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    57
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    58
Lets write some piece of code to check this out .
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    59
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    60
a=False
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    61
b=True
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    62
c=True
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    63
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    64
To check how precedence changes with parenthesis . We will try two expressions and their evaluation.
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    65
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    66
do
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    67
(a and b) or c 
73
9dffd11728d2 Started on day2 . Adding a script on basic python
amit@shrike.aero.iitb.ac.in
parents:
diff changeset
    68
 
78
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    69
This expression gives the value True
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    70
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    71
where as the expression a and (b or c) gives the value False .
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    72
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    73
Now we will have a look at strings 
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    74
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    75
type 
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    76
w="hello"
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    77
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    78
w is now a string variable with the value "hello"
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    79
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    80
printing out w[0] + w[2] + w[-1] gives hlo if you notice the expression for accessing characters of a string is similar to lists . 
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    81
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    82
Also functions like len work with strings just like the way they did with lists
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    83
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    84
Now lets try changing a character in the string in the same way we change lists .
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    85
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    86
type :
93
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
    87
w[0]='H'  
78
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    88
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    89
oops this gives us a Type Error . Why? Because string are immutable . You can change a string simply by assigning a new element to it . This and some other features specific to string processing make string a different kind of data structure than lists .  
099a2cc6c7d2 Added a bit more to script of basic python . Session one day 2
amit@shrike.aero.iitb.ac.in
parents: 73
diff changeset
    90
 
93
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
    91
Now lets see some of the ways in which you can modify strings and other methods related to strings .
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
    92
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
    93
Type :
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
    94
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
    95
a = 'Hello world' 
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
    96
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
    97
To check if a particular string starts with a particular substring you can check that with startswith method
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
    98
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
    99
a.startswith('Hell')
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   100
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   101
Depending on whether the string starts with that substring the function returns true or false
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   102
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   103
same is the case a.endwith('ld')
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   104
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   105
a.upper()
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   106
 returns another string that is all the letters of given string capitalized
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   107
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   108
similarly a.lower returns all small letters .
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   109
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   110
Earlier we showed you how to see documentations of functions . You can see the documentation of the lower function by doing a.lower?
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   111
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   112
You can use a.join to joing a list of strings to one string using a given string as connector . 
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   113
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   114
for example 
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   115
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   116
type :
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   117
', '.join(['a','b','c'])
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   118
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   119
In this case strings are joined over , and space
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   120
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   121
Python supports formatting values into strings. Although this can include very complicated expressions, the most basic usage is to insert values into a string with the %s placeholder. %d can be used for formatting things like integers and %f for floats
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   122
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   123
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   124
Their are many other string formatting options you can look at http://docs.python.org/library/stdtypes.html for more information on other options available for string formatting.
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   125
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   126
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   127
Operators ---- Probably can be a different chapter .
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   128
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   129
We will start the discussion on operators first with arithmetic operators .
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   130
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   131
% can be used for remainder for example
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   132
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   133
864675 % 10 gives remainder 5 
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   134
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   135
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   136
you can use 2 *'s for power operation 
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   137
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   138
for example 4 ** 3 gives the result 64
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   139
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   140
One thing one should notice is the type of result depends on the types of input for example :
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   141
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   142
17 / 2 both the values being integer gives the integer result 2
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   143
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   144
however the result when one or two of the operators are float is float for example:
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   145
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   146
17/2.0 
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   147
8.5
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   148
17.0/2.0 
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   149
8.5 
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   150
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   151
 
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   152
 
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   153
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   154
bdee3ead116d Some more additions to basic python ended discussion on string started operators
amit@shrike.aero.iitb.ac.in
parents: 78
diff changeset
   155