Changes to basic data-types.
authorPuneeth Chaganti <punchagan@fossee.in>
Tue, 09 Nov 2010 14:57:08 +0530
changeset 412 bb45826efe74
parent 411 e227c45b0c3f
child 413 da1f270b07b7
child 418 8a42b4203f6d
Changes to basic data-types.
basic-data-type/script.rst
basic-data-type/slides.org
basic-data-type/slides.tex
--- a/basic-data-type/script.rst	Tue Nov 09 10:56:50 2010 +0530
+++ b/basic-data-type/script.rst	Tue Nov 09 14:57:08 2010 +0530
@@ -16,8 +16,6 @@
    External Reviewer   :
    Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
 
-.. #[Puneeth: Fill in pre-requisites.]
-
 Hello friends and welcome to the tutorial on Basic Data types and operators
 in Python.
 
@@ -40,13 +38,6 @@
   * string
   * tuple
 
-.. #[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.
-
-
-
 First we will explore python data structures in the domain of numbers.
 There are three built-in data types in python to represent numbers.
 
@@ -58,12 +49,6 @@
   * float 
   * complex 
 
-.. #[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 int. ::
 
    a = 13
@@ -78,17 +63,14 @@
    type(a)
    <type 'int'>
 
-This means that a is a type of int. Being an int data type in python
-means that there are various functions that this variable has to manipulate
-in different ways. You can explore these by doing,
+This means that a is a type of int. There are lot of functions associated
+with the int datatype, to manipulate it in different ways. These can be
+explored 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 - ]
-
 *int* datatype can hold integers of any size lets see this by an example.
+::
 
   b = 99999999999999999999
   b
@@ -97,11 +79,6 @@
 not complain. This is because python's int data-type can hold integers of any
 size.
 
-.. #[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.]
-
 Let us now look at the float data-type. 
 
 Decimal numbers in python are represented by the float data-type ::
@@ -109,10 +86,10 @@
   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 approximation. 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 ::
 
@@ -120,7 +97,7 @@
 
 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 ::
+have a lot of functions specific to them. Let us look at these ::
 
   c.<Tab>
 
@@ -174,10 +151,6 @@
 
 The results are self explanatory.
 
-.. #[Puneeth: Why does booleans bring us to precedence? I don't see the
-.. connection. Am I missing something?]
-
-
 What if you want to apply one operator before another.
 
 Well you can use parenthesis for precedence.
@@ -189,8 +162,6 @@
   c=True
 
 
-.. #[Puneeth: Consistency. In[]: is not present at other places.]
-
 To check how precedence changes with parenthesis, we will try two
 expressions and their evaluation.
 
@@ -210,14 +181,12 @@
 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 addition ::
 
   23 + 74
 
 '-' for subtraction ::
+
   23 - 56
 
 '*' for multiplication ::
@@ -264,26 +233,26 @@
 
    a=a/23
 
-Following is an (are) exercise(s) that you must do. 
+Following is are exercises that you must do. 
 
 %% %% Using python find sqaure root of 3?
+
+%% %% Is 3**1/2 and 3**0.5 same
+
+Please, pause the video here. Do the exercises and then continue.
+
 ::
 
    3**0.5
 
-%% %% Is 3**1/2 and 3**0.5 same
 ::
     No,One gives an int answer and the other float        
 
-Please, pause the video here. Do the exercises and then continue.
-
 
 Lets now discuss sequence data types in Python. Sequence data types
 are those in which elements are kept in a sequential order and all the 
 elements are accessed using index numbers.
 
-.. #[Puneeth: fix the last sentence - it sounds incomplete]
-
 {{{ slide introducing sequence datatype }}}
 
 The sequence datatypes in Python are ::
@@ -310,8 +279,6 @@
  var_list = [1, 1.2, [1,2]]	
  var_list
 
-.. #[Puneeth: some continuity, when jumping to strings?]
-
 Lets look at another sequence data type, strings
 
 type :: 
@@ -329,12 +296,8 @@
    l="Let's see how to include a single quote"
    m='''"Let's see how to include both"'''
 
-.. #[Puneeth: Contain's? That's not a word!]
-
 As you can see, single quotes are used as delimiters usually.
 
-.. #[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.
@@ -403,10 +366,8 @@
    sorted(num_list)
    
 
-As a consequence of there order we can access a group of elements 
-in a sequence,together. This is called slicing and striding.
-
-.. #[Puneeth: Fix the sentence above. ]
+As a consequence of their order, we can access a group of elements in a
+sequence, together. This is called slicing and striding.
 
 First lets discuss Slicing, 
 
@@ -563,8 +524,8 @@
 Please, pause the video here. Do the exercise(s) and then continue. 
 
 
-
-In this tutorial we have discussed 
+This brings us to the end of the tutorial. In this tutorial we have
+discussed
 
 1. Number Datatypes , integer,float and complex 
 2. Boolean and datatype and operators
@@ -574,16 +535,6 @@
 6. Finding length , sorting and reversing operations on sequences.
 7. Immutability.
 
-
-
-
-.. #[Nishanth]: string to list is fine. But list to string can be left for
-                string manipulations. Just say it requires some string 
-                manipulations and leave it there.
-
-.. #[Nishanth]: Where is the summary
-                There are no exercises in the script
-
 {{{ Show the "sponsored by FOSSEE" slide }}}
 
 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
--- a/basic-data-type/slides.org	Tue Nov 09 10:56:50 2010 +0530
+++ b/basic-data-type/slides.org	Tue Nov 09 14:57:08 2010 +0530
@@ -21,47 +21,46 @@
 #+TITLE: Plotting Data 
 #+AUTHOR: FOSSEE
 #+DATE: 2010-09-14 Tue
-#+EMAIL:     info@fossee.in
+#+EMAIL: info@fossee.in
 
 #+DESCRIPTION: 
 #+KEYWORDS: 
 #+LANGUAGE:  en
-#+OPTIONS:   H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
+#+OPTIONS:   H:1 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
 #+OPTIONS:   TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
-
+#+STARTUP:    align fold nodlcheck hidestars oddeven lognotestate
 
 * Outline 
 ** Datatypes in Python
-    - Numbers
-    - Boolean
-    - Sequence
-**  Operators in Python
-    - Arithmetic Operators
-    - Boolean Operators
+*** Numbers
+*** Boolean
+*** Sequence
+** Operators in Python
+*** Arithmetic Operators
+*** Boolean Operators
 ** Python Sequence Datatypes
-   - list
-   - string
-   - tuple
+*** list
+*** string
+*** tuple
 
 * Numbers
-  - Integers
-  - Float
-  - Complex
+  - int
+  - float
+  - complex
 * Question 1
    - Find the absolute value of 3+4j 
 * Solution 1
-
-        abs(3+4j)
-
+  #+begin_src python
+    abs(3+4j)
+  #+end_src python
 * Question 2
   - What is the datatype of number 999999999999999999? Is it
 not int?
 
 * Solution 2
-        
-        - Long
-        - Large integers numbers are internally stored in python
-        as Long datatype.  
+  - Long
+  - Large integers numbers are internally stored in python as Long
+    datatype.
 
 
 * Boolean
@@ -70,16 +69,16 @@
     In []: f=False
   #+end_src
 
-* Question 1
+* Question 3
   - Using python find sqaure root of 3?
 
-* Solution 1
+* Solution 3
 
   - 3**0.5
 
-* Question 2
+* Question 4
   - Is 3**1/2 and 3**0.5 same
-* Solution 2
+* Solution 4
   - No,One gives an int answer and the other float        
 
 * Sequence Data types
@@ -93,71 +92,51 @@
 
 * All are Strings
    #+begin_src python 
-      k='Single quote'
-      l="Double quote contain's single quote"
-      m='''"Contain's both"'''
+      k = 'Single quote'
+      l = "Double quote contain's single quote"
+      m = '''"Contain's both"'''
 
     #+end_src 
 * Immutabilty Error
    #+begin_src python
       In []: greeting_string[1]='k'
-      ---------------------------------------------------------------------------
-      TypeError                                 Traceback (most recent call       last)
+      -------------------------------------------------------
+      TypeError           Traceback (most recent call last)
 
-      /home/amit/st-scripts/basic-data-type/<ipython console> in <module>()
+      /home/fossee/<ipython console> in <module>()
 
       TypeError: 'str' object does not support item assignment
    #+end_src 
 
-* Question 1
-   - Check if 3 is an element of the list [1,7,5,3,4]. In case
-it is change it to 21.
+* Question 5
+  Check if 3 is an element of the list [1,7,5,3,4]. In case it is
+change it to 21.
 
-* Solution 1
+* Solution 5
      #+begin_src python
         l=[1,7,5,3,4]
         3 in l
         l[3]=21
         l
      #+end_src
-* Question 2
-  - Convert the string "Elizabeth is queen of england" to
-"Elizabeth is queen"
+* Question 6
+  Convert the string ~"Elizabeth is queen of england"~ to ~"Elizabeth is
+queen"~
 
-* Solution 2
+* Solution 6
      #+begin_src python
-    s="Elizabeth is queen of england"                                                                                                                 
-    stemp=s.split()                                                                                                                                   
+    s = "Elizabeth is queen of england"                                                                                                                 
+    stemp = s.split()                                                                                                                                   
     ' '.join(stemp[:3])                                                                                                                               
     #+end_src 
 * Summary 
-   #+begin_src python 
-    a=73
-    b=3.14
-    c=3+4j
-
-   #+end_src
-* Summary Contd.
-   #+begin_src python
-     t=True
-     f=False
-     t and f
-   #+end_src
-* Summary Contd.
-   #+begin_src python 
-     l= [2,1,4,3]
-     s='hello'
-     tu=(1,2,3,4)
-   #+end_src
-* Summary Contd.
-   #+begin_src python 
-     tu[-1]
-     s[1:-1]
-   #+end_src
-* Summary Contd.
-   #+begin_src python  
-     Sorted(l)
-   #+end_src
+  - Number Datatypes -- integer,float and complex 
+  - Boolean and datatype and operators
+  - Sequence data types -- List, String and Tuple
+  - Accesing sequence
+  - Slicing sequences
+  - Finding length, sorting and reversing operations on sequences
+  - Immutability
 * Thank you!
 #+begin_latex
   \begin{block}{}
--- a/basic-data-type/slides.tex	Tue Nov 09 10:56:50 2010 +0530
+++ b/basic-data-type/slides.tex	Tue Nov 09 14:57:08 2010 +0530
@@ -1,4 +1,4 @@
-% Created 2010-11-09 Tue 01:27
+% Created 2010-11-09 Tue 14:56
 \documentclass[presentation]{beamer}
 \usepackage[latin1]{inputenc}
 \usepackage[T1]{fontenc}
@@ -8,7 +8,6 @@
 \usepackage{float}
 \usepackage{wrapfig}
 \usepackage{soul}
-\usepackage{t1enc}
 \usepackage{textcomp}
 \usepackage{marvosym}
 \usepackage{wasysym}
@@ -41,7 +40,6 @@
 
 
 
-
 \begin{frame}
 \frametitle{Outline}
 \label{sec-1}
@@ -50,29 +48,36 @@
 \item Datatypes in Python
 \label{sec-1_1}%
 \begin{itemize}
-\item Numbers
-\item Boolean
-\item Sequence
-\end{itemize}
 
+\item Numbers\\
+\label{sec-1_1_1}%
+\item Boolean\\
+\label{sec-1_1_2}%
+\item Sequence\\
+\label{sec-1_1_3}%
+\end{itemize} % ends low level
 
 \item Operators in Python
 \label{sec-1_2}%
 \begin{itemize}
-\item Arithmetic Operators
-\item Boolean Operators
-\end{itemize}
 
+\item Arithmetic Operators\\
+\label{sec-1_2_1}%
+\item Boolean Operators\\
+\label{sec-1_2_2}%
+\end{itemize} % ends low level
 
 \item Python Sequence Datatypes
 \label{sec-1_3}%
 \begin{itemize}
-\item list
-\item string
-\item tuple
-\end{itemize}
 
-
+\item list\\
+\label{sec-1_3_1}%
+\item string\\
+\label{sec-1_3_2}%
+\item tuple\\
+\label{sec-1_3_3}%
+\end{itemize} % ends low level
 \end{itemize} % ends low level
 \end{frame}
 \begin{frame}
@@ -80,9 +85,9 @@
 \label{sec-2}
 
 \begin{itemize}
-\item Integers
-\item Float
-\item Complex
+\item int
+\item float
+\item complex
 \end{itemize}
 \end{frame}
 \begin{frame}
@@ -93,12 +98,14 @@
 \item Find the absolute value of 3+4j
 \end{itemize}
 \end{frame}
-\begin{frame}
+\begin{frame}[fragile]
 \frametitle{Solution 1}
 \label{sec-4}
 
-
-        abs(3+4j)
+\lstset{language=Python}
+\begin{lstlisting}
+abs(3+4j)
+\end{lstlisting}
 \end{frame}
 \begin{frame}
 \frametitle{Question 2}
@@ -114,25 +121,25 @@
 \frametitle{Solution 2}
 \label{sec-6}
 
-        
+
 \begin{itemize}
 \item Long
-\item Large integers numbers are internally stored in python
+\item Large integers numbers are internally stored in python as Long
+    datatype.
 \end{itemize}
-
-        as Long datatype.  
 \end{frame}
 \begin{frame}[fragile]
 \frametitle{Boolean}
 \label{sec-7}
 
-\begin{verbatim}
+\lstset{language=Python}
+\begin{lstlisting}
 In []: t=True
 In []: f=False
-\end{verbatim}
+\end{lstlisting}
 \end{frame}
 \begin{frame}
-\frametitle{Question 1}
+\frametitle{Question 3}
 \label{sec-8}
 
 \begin{itemize}
@@ -140,7 +147,7 @@
 \end{itemize}
 \end{frame}
 \begin{frame}
-\frametitle{Solution 1}
+\frametitle{Solution 3}
 \label{sec-9}
 
 
@@ -149,7 +156,7 @@
 \end{itemize}
 \end{frame}
 \begin{frame}
-\frametitle{Question 2}
+\frametitle{Question 4}
 \label{sec-10}
 
 \begin{itemize}
@@ -157,7 +164,7 @@
 \end{itemize}
 \end{frame}
 \begin{frame}
-\frametitle{Solution 2}
+\frametitle{Solution 4}
 \label{sec-11}
 
 \begin{itemize}
@@ -192,117 +199,82 @@
 \frametitle{All are Strings}
 \label{sec-13}
 
-\begin{verbatim}
-k='Single quote'
-l="Double quote contain's single quote"
-m='''"Contain's both"'''
-\end{verbatim}
+\lstset{language=Python}
+\begin{lstlisting}
+k = 'Single quote'
+l = "Double quote contain's single quote"
+m = '''"Contain's both"'''
+\end{lstlisting}
 \end{frame}
 \begin{frame}[fragile]
 \frametitle{Immutabilty Error}
 \label{sec-14}
 
-\begin{verbatim}
+\lstset{language=Python}
+\begin{lstlisting}
 In []: greeting_string[1]='k'
----------------------------------------------------------------------------
-TypeError                                 Traceback (most recent call       last)
+-------------------------------------------------------
+TypeError           Traceback (most recent call last)
 
-/home/amit/st-scripts/basic-data-type/<ipython console> in <module>()
+/home/fossee/<ipython console> in <module>()
 
 TypeError: 'str' object does not support item assignment
-\end{verbatim}
+\end{lstlisting}
 \end{frame}
 \begin{frame}
-\frametitle{Question 1}
+\frametitle{Question 5}
 \label{sec-15}
 
-\begin{itemize}
-\item Check if 3 is an element of the list [1,7,5,3,4]. In case
-\end{itemize}
-
-it is change it to 21.
+  Check if 3 is an element of the list [1,7,5,3,4]. In case it is
+change it to 21.
 \end{frame}
 \begin{frame}[fragile]
-\frametitle{Solution 1}
+\frametitle{Solution 5}
 \label{sec-16}
 
-\begin{verbatim}
+\lstset{language=Python}
+\begin{lstlisting}
 l=[1,7,5,3,4]
 3 in l
 l[3]=21
 l
-\end{verbatim}
+\end{lstlisting}
 \end{frame}
 \begin{frame}
-\frametitle{Question 2}
+\frametitle{Question 6}
 \label{sec-17}
 
-\begin{itemize}
-\item Convert the string ``Elizabeth is queen of england'' to
-\end{itemize}
-
-``Elizabeth is queen''
+  Convert the string \~{}''Elizabeth is queen of england''\~{} to \~{}''Elizabeth is
+queen''\~{}
 \end{frame}
 \begin{frame}[fragile]
-\frametitle{Solution 2}
+\frametitle{Solution 6}
 \label{sec-18}
 
-\begin{verbatim}
-s="Elizabeth is queen of england"                                                                                                                 
-stemp=s.split()                                                                                                                                   
+\lstset{language=Python}
+\begin{lstlisting}
+s = "Elizabeth is queen of england"                                                                                                                 
+stemp = s.split()                                                                                                                                   
 ' '.join(stemp[:3])
-\end{verbatim}
+\end{lstlisting}
 \end{frame}
-\begin{frame}[fragile]
+\begin{frame}
 \frametitle{Summary}
 \label{sec-19}
 
-\begin{verbatim}
-a=73
-b=3.14
-c=3+4j
-\end{verbatim}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Summary Contd.}
-\label{sec-20}
-
-\begin{verbatim}
-t=True
-f=False
-t and f
-\end{verbatim}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Summary Contd.}
-\label{sec-21}
-
-\begin{verbatim}
-l= [2,1,4,3]
-s='hello'
-tu=(1,2,3,4)
-\end{verbatim}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Summary Contd.}
-\label{sec-22}
-
-\begin{verbatim}
-tu[-1]
-s[1:-1]
-\end{verbatim}
-\end{frame}
-\begin{frame}[fragile]
-\frametitle{Summary Contd.}
-\label{sec-23}
-
-\begin{verbatim}
-Sorted(l)
-\end{verbatim}
+\begin{itemize}
+\item Number Datatypes -- integer,float and complex
+\item Boolean and datatype and operators
+\item Sequence data types -- List, String and Tuple
+\item Accesing sequence
+\item Slicing sequences
+\item Finding length, sorting and reversing operations on sequences
+\item Immutability
+\end{itemize}
 \end{frame}
 \begin{frame}
 \frametitle{Thank you!}
-\label{sec-24}
+\label{sec-20}
 
   \begin{block}{}
   \begin{center}