Reviewed Basic datatypes LO.
authorPuneeth Chaganti <punchagan@fossee.in>
Tue, 19 Oct 2010 14:26:02 +0530
changeset 337 c65d0d9fc0c8
parent 326 c4cb18752ade
child 338 e4a7d0924143
Reviewed Basic datatypes LO.
basic-data-type/questions.rst
basic-data-type/script.rst
basic-data-type/slides.org
--- a/basic-data-type/questions.rst	Thu Oct 14 14:11:54 2010 +0530
+++ b/basic-data-type/questions.rst	Tue Oct 19 14:26:02 2010 +0530
@@ -3,6 +3,9 @@
 
 .. A mininum of 8 questions here (along with answers)
 
+.. #[Puneeth: ``Answer: Any size.``. Demarcate the answer from the
+.. question.]
+
 1. How large can an integer in Python be?
 
    Any Size.
@@ -18,11 +21,10 @@
    c= 3.2 + 4.6j
 
 
-
 3. Look at the following piece of code ::
    
-   In []: f or t 
-   Out[]:True
+     In []: f or t 
+     Out[]:True
 
    What can you comment about the data type of f and t ? 
 
@@ -33,12 +35,15 @@
 
 5. Look at the following sequence ::
 
-   In []:t=true
-   NameError: name 'true' is not defined
+     In []:t=true
+     NameError: name 'true' is not defined
 
    What might be the reason for error here?
 
-   In this scenario , it seems the programmer wanted to create a variable t with the boolean value True with a capital T. Since no variable by the name true(small t) is known to the interpreter it gives a NameError. 
+   In this scenario , it seems the programmer wanted to create a
+   variable t with the boolean value True with a capital T. Since no
+   variable by the name true(small t) is known to the interpreter it
+   gives a NameError.
 
 
 6. Put the following string in a variable quotation.
@@ -48,11 +53,14 @@
 
 7. Given a tuple ::
 
-   tup=(7,4,2,1,3,6,5,8)
-   tup[-2]
+     tup=(7,4,2,1,3,6,5,8)
+     tup[-2]
   
    5
 
+.. #[Puneeth: ``Answer: Any size.``. Demarcate the answer from the
+.. question.]
+
 8. What is the syntax for checking containership in Python?::
 
    element in sequence 
@@ -78,6 +86,9 @@
 1. Given two lists for example,
    list1=[1,2,3,4] and list2=[1,2,3,4,5,6,7] write a program to remove one list from the other.
 
+.. #[Puneeth: dependency LOs?]
 
 #. Write a program to check if a string is palindrome?
 
+.. #[Puneeth: comparison has not been taught, has it? does this depend
+.. on any other LO?]
--- a/basic-data-type/script.rst	Thu Oct 14 14:11:54 2010 +0530
+++ b/basic-data-type/script.rst	Tue Oct 19 14:26:02 2010 +0530
@@ -13,16 +13,24 @@
    Internal Reviewer   : 
    External Reviewer   :
    Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
-Hello friends and welcome to the tutorial on Basic Data types and operators in Python.  
+
+.. #[Puneeth: Fill in pre-requisites.]
+
+Hello friends and welcome to the tutorial on Basic Data types and operators
+in Python.
+
 {{{ Show the slide containing title }}}
 
 {{{ Show the slide containing the outline slide }}}
 
-In this tutorial, we shall look at::
+In this tutorial, we shall look at
 
  * Datatypes in Python
  * Operators in Python
 
+.. #[Puneeth: Use double colon only for code blocks.]
+.. #[Puneeth: include more details in the outline.]
+
 with a little hands-on on how they can be applied to the different data types.
 
 
@@ -34,9 +42,15 @@
 
 These are:
 
-  * Integers 
-  * float and 
-  * Complex 
+  * int for integers
+  * float for floating point numbers and 
+  * complex for complex numbers
+
+.. #[Puneeth: Changed to  int, float and complex.]
+
+.. #[Puneeth: Loss of consistency. You talk of built-in data types, but
+.. then you were calling them integers, floats and complex. Clean up
+.. required.]
 
 Lets first talk about integers. ::
 
@@ -44,8 +58,7 @@
    a
 
 
-Thats it, there we have our first integer variable a.
-
+Now, we have our first integer variable a.
 
 
 If we now see ::
@@ -53,51 +66,58 @@
    type(a)
    <type 'int'>
 
-This means that a is a type of int. Being an int data structure 
-in python means that there are various functions that this variable
-has to manipulate it different ways. You can explore these by doing,
+This means that a is a type of int. Being an int data structure in python
+means that there are various functions that this variable has to manipulate
+it different ways. You can explore these by doing,
 
   a.<Tab>
 
-
+.. #[Puneeth: Why are we suddenly talking of limits?
+.. Something like this would be better. 
+.. int data-type can hold integers of any size. for example - ]
 
 Lets see the limits of this int.
 
   b = 99999999999999999999
   b
 
-As you can see even when we put a value of 9 repeated 20 times 
-python did not complain. However when you asked python to print
-the number again it put a capital L at the end. Now if you check
-the type of this variable b, ::
+As you can see even when we put a value of 9 repeated 20 times python did
+not complain. However when you asked python to print the number again it
+put a capital L at the end. Now if you check the type of this variable b,
+::
 
   type(b)
   <type 'long'>
 
 
-The reason for this is that python recognizes large integer numbers
-by the data type long. However long type and integer type share there 
-functions and properties.
+The reason for this is that python recognizes large integer numbers by the
+data type long. However long type and integer type share there functions
+and properties.
 
-Lets now try out the second type in list called float.
+.. #[Puneeth: again, the clean-up that I talked of above. Decide if you are
+.. talking about the different type of numbers and the datatypes that are
+.. used to represent them or if you are talking of the data-types and what
+.. kind of numbers they represent. I think you should choose the former.]
 
-Decimal numbers in python are recognized by the term float ::
+Let us now look at the float data-type. 
+
+Decimal numbers in python are represented by the float data-type ::
 
   p = 3.141592
   p
 
-If you notice the value of output of p isn't exactly equal to p. This
-is because computer saves floating point values in a specific
-format. There is always an aproximationation. This is why we should
-never rely on equality of floating point numbers in a program.
+If you notice the value of output of p isn't exactly equal to p. This is
+because computer saves floating point values in a specific format. There is
+always an aproximationation. This is why we should never rely on equality
+of floating point numbers in a program.
 
 The last data type in the list is complex number ::
 
   c = 3.2+4.6j
 
-as simple as that so essentialy its just a combination of two floats the 
-imaginary part being defined by j notation instead of i. Complex numbers have a lot of functions specific to them.
-Lets check these ::
+as simple as that so essentialy its just a combination of two floats the
+imaginary part being defined by j notation instead of i. Complex numbers
+have a lot of functions specific to them. Lets check these ::
 
   c.<Tab>
 
@@ -132,21 +152,26 @@
   f and t 
 
 
-  
-The results are explanotary in themselves.
+The results are self explanatory.
 
-The usage of boolean brings us to an interesting question of precendence.
-What if you want to apply one operator before another. 
+.. #[Puneeth: Why does booleans bring us to precedence? I don't see the
+.. connection. Am I missing something?]
+
+The usage of boolean brings us to an interesting question of precedence.
+What if you want to apply one operator before another.
 
 Well you can use parenthesis for precedence.
 
-Lets write some piece of code to check this out.
+Lets write some piece of code to check this out.::
 
   In[]: a=False 
   In[]: b=True 
   In[]: c=True
 
-To check how precedence changes with parenthesis. We will try two
+
+.. #[Puneeth: Consistency. In[]: is not present at other places.]
+
+To check how precedence changes with parenthesis, we will try two
 expressions and their evaluation.
 
 one ::
@@ -162,19 +187,24 @@
 gives the value False.
 
 
-Lets now look at some operators available in Python to manipulate these data types.
+Let's now look at some operators available in Python to manipulate
+these data types.
 
-
+.. #[Puneeth: A mention of other operators would be good? Starting
+.. with % and ** is a bit weird.]
 
 Python uses % for modulo operation ::
 
     87 % 6
+
 and two stars for a exponent. ::
 
     7**8
 
 
-In case one wishes to use the current value of variable in which the result is stored in the expression one can do that by putting the operator before `equal to`. ::
+In case one wishes to use the current value of variable in which the result
+is stored in the expression one can do that by putting the operator before
+`equal to`. ::
 
    a=73
    a*=34
@@ -191,22 +221,22 @@
 
    a=a/23
 
-
-Lets now discuss sequence data stypes in python. Sequence 
-datatypes are those in which elements are kept in a sequential 
-order. All the elements accessed using index. 
+Lets now discuss sequence data types in Python. Sequence data types
+are those in which elements are kept in a sequential order. All the
+elements accessed using index.
 
+.. #[Puneeth: fix the last sentence - it sounds incomplete]
 
-{{{ slide to for memory aid }}}
+{{{ slide for memory aid }}}
 
-The sequence datatypes in python are ::
+The sequence datatypes in Python are ::
 
  * list
  * string
  * tuple
 
-The list type is a container that holds a number of other 
-objects, in the given order.
+The list type is a container that holds a number of other objects, in the
+given order.
 
 We create our first list by typing :: 
   
@@ -214,19 +244,18 @@
   num_list
 
 
-Items enclosed in square brackets separated by comma 
-constitutes a list.
+Items enclosed in square brackets separated by comma constitutes a list.
 
-Lists can store data of any type in them. 
+Lists can store data of any type in them.
 
 We can have a list something like ::
 
  var_list = [1, 1.2, [1,2]]	
  var_list
 
-
+.. #[Puneeth: some continuity, when jumping to strings?]
 
-Now we will have a look at strings 
+Now we will have a look at strings
 
 type :: 
 
@@ -243,20 +272,24 @@
   In[]: l="Double quote contain's single quote"
   In[]: m='''"Contain's both"'''
 
+.. #[Puneeth: Contain's? That's not a word!]
+
 Thus, single quotes are used as delimiters usually.
-When a string contains a single quote, double quotes are used as delimiters.
-When a string quote contains both single and double quotes, triple quotes are
-used as delimiters.
+
+.. #[Puneeth: Thus?]
+
+When a string contains a single quote, double quotes are used as
+delimiters. When a string quote contains both single and double quotes,
+triple quotes are used as delimiters.
 
 The last in the list of sequence data types is tuple.
 
-To create a tuple  we use normal brackets '('
-unlike '[' for lists.::
+To create a tuple we use normal brackets '(' unlike '[' for lists.::
 
   In[]: num_tuple = (1, 2, 3, 4, 5, 6, 7, 8)
   
-Because of their sequential property there are certain functions and 
-operations we can apply to all of them. 
+Because of their sequential property there are certain functions and
+operations we can apply to all of them.
 
 
 
@@ -273,9 +306,9 @@
   In[]: num_tuple[-3]
 
 
-Indexing starts from 0 from left to right and from -1 when accessing
-lists in reverse. Thus num_list[2] refers to the third element 3. 
-and greetings [-2] is the second element from the end , that is 'l'. 
+Indexing starts from 0 from left to right and from -1 when accessing lists
+in reverse. Thus num_list[2] refers to the third element 3. and greetings
+[-2] is the second element from the end , that is 'l'.
 
 
 
@@ -287,7 +320,7 @@
      In[]: t2=(3,4,6,7)
      In[]: num_tuple+t2
 
-len function gives the length  ::
+len function gives the length ::
 
   In[]: len(num_list)
   In[]: len(greeting_string)
@@ -303,7 +336,7 @@
 
 We see that it gives True and False accordingly.
 
-Find maximum using max function and minimum using min:: 
+Find maximum using max function and minimum using min::
 
   In[]: max(num_tuple)
   In[]: min(greeting_string)
@@ -316,6 +349,8 @@
 As a consequence of the order one we access a group of elements together.
 This is called slicing and striding.
 
+.. #[Puneeth: Fix the sentence above. ]
+
 First Slicing 
 
 Given a list ::
@@ -328,8 +363,9 @@
 
   In[]: j[1:4]
 
-The syntax for slicing is sequence variable name square bracket
-first element index, colon, second element index.The last element however is notincluded in the resultant list::
+The syntax for slicing is, sequence variable name square bracket first
+element index, colon, second element index. The last element however is not
+included in the resultant list::
 
 
   In[]: j[:4]
@@ -337,6 +373,8 @@
 If first element is left blank default is from beginning and if last
 element is left blank it means till the end.
 
+::
+
  In[]: j[1:]
 
  In[]: j[:]
@@ -351,12 +389,13 @@
   new_num_list[1:8:2]
   [2, 4, 6, 8]
 
-The colon two added in the end signifies all the alternate elements. This is why we call this concept
-striding because we move through the list with a particular stride or step. The step in this example
-being 2. 
+The colon two added in the end signifies all the alternate elements. This
+is why we call this concept striding because we move through the list with
+a particular stride or step. The step in this example being 2.
 
-We have talked about many similar features of lists, strings and tuples. But there are many important
-features in lists that differ from strings and tuples. Lets see this by example.::
+We have talked about many similar features of lists, strings and tuples.
+But there are many important features in lists that differ from strings and
+tuples. Lets see this by example.::
 
   In[]: new_num_list[1]=9
   In[]: greeting_string[1]='k'
@@ -365,18 +404,21 @@
 
 
 
-As you can see while the first command executes with out a problem there is an error on the second one.
+As you can see while the first command executes with out a problem there is
+an error on the second one.
   
 Now lets try ::
 
   In[]: new_tuple[1]=5
 
-Its the same error. This is because strings and tuples share the property of being immutable.
-We cannot change the value at a particular index just by assigning a new value at that position.
+Its the same error. This is because strings and tuples share the property
+of being immutable. We cannot change the value at a particular index just
+by assigning a new value at that position.
 
 
-We have looked at different types but we need to convert one data type into another. Well lets one
-by one go through methods by which we can convert one data type to other:
+We have looked at different types but we need to convert one data type into
+another. Well lets one by one go through methods by which we can convert
+one data type to other:
 
 We can convert all the number data types to one another ::
 
@@ -384,21 +426,25 @@
   d=float(i)
   d  
 
-Python has built in functions int, float and complex to convert one number type
-data structure to another.
+Python has built in functions int, float and complex to convert one number
+type data structure to another.
+
+::
 
   dec=2.34
   dec_con=int(dec)
   dec_con
 
 
-As you can see the decimal part of the number is simply stripped to get the integer.::
+As you can see the decimal part of the number is simply stripped to get the
+integer.::
 
   com=2.3+4.2j
   float(com)
   com
 
-In case of complex number to floating point only the real value of complex number is taken.
+In case of complex number to floating point only the real value of complex
+number is taken.
 
 Similarly we can convert list to tuple and tuple to list ::
   
@@ -407,15 +453,17 @@
   tupl=(3,23,4,56)
   lst=list(tuple)
 
-However string to list and list to string is an interesting problem.
-Lets say we have a string ::
+However converting a string to a list and a list to a string is an
+interesting problem. Let's say we have a string ::
 
   In: somestring="Is there a way to split on these spaces."
   In: somestring.split()
 
 
-This produces a list with the string split at whitespace.
-similarly we can split on some other character.
+This produces a list with the string split at whitespace. Similarly we can
+split on some other character.
+
+::
 
   In: otherstring="Tim,Amy,Stewy,Boss"
 
@@ -464,4 +512,10 @@
 Thank You.
 
 
-
+.. 
+   Local Variables:
+   mode: rst
+   indent-tabs-mode: nil
+   sentence-end-double-space: nil
+   fill-column: 75
+   End:
--- a/basic-data-type/slides.org	Thu Oct 14 14:11:54 2010 +0530
+++ b/basic-data-type/slides.org	Tue Oct 19 14:26:02 2010 +0530
@@ -67,6 +67,9 @@
 
 ** Sorted(l)
 ** reversed(s)
-  
+
+* COMMENT 
+# [Puneeth: Where is the last slide?]
+# [Puneeth: Why don't you use the template slides.org?]