Completed functions.org and added functions.tex file.
authorSantosh G. Vattam <vattam.santosh@gmail.com>
Wed, 05 May 2010 17:31:32 +0530
changeset 120 50716c7c4c0c
parent 119 7dc53e6c8065
child 121 331c5fdc06d4
Completed functions.org and added functions.tex file.
functions.org
ipython-tut.txt
presentations/functions.tex
--- a/functions.org	Tue May 04 17:21:12 2010 +0530
+++ b/functions.org	Wed May 05 17:31:32 2010 +0530
@@ -60,8 +60,8 @@
     We shall now look at default arguments. 
     [show slide with examples of functions with default arguments]
     The split function has been used in two different ways in the
-    previous tutorials - one for splitting on spaces and the other for
-    splitting on semicolons. 
+    given example - one for splitting on spaces and the other for
+    splitting on commas.
 
     The function split is being called with no arguments and one
     argument, respectively. In the first case, white space is being
@@ -83,7 +83,7 @@
     We have already looked at functions and keyword arguments in these
     examples. loc, linewidth, xy, labels are all keywords. 
 
-    Let's now customize our function so that it displays a custom 
+    Let's now edit our function so that it displays a custom 
     greeting message as well. 
 
     def welcome( greet = 'Hello', name = 'World!'):
@@ -99,12 +99,25 @@
     in any order and removes the need to remember the order of arguments
     in the function definition. 
 
-    
+    Let's now write a new function 
+
+    def per_square(n):
+        i = 1
+	while ( i*i < n ):
+	    i += 1
+	return i*i == n, i
+
+    What does this function do? It checks if the given number is a perfect square.
+    If it is, then the function returns True along with the square root of
+    the given number. If the number is not a perfect square it returns
+    False and the square root of the next perfect square.
+
+    Please observe that this function returns 2 values.
     In Python there is no restriction on the number of values returned by
-    a function. When a function returns more than one value, the multiple
+    a function. Whenever a function has to return more than one value, the multiple
     values are packed into one single tuple and that single tuple is returned.
 
-    We come to the end of this tutorial on functions. In this tutorial
+    With this we come to the end of this tutorial on functions. In this tutorial
     we have learnt about functions in a greater detail. We looked at
     how to define functions, calling them, default and keyword
     arguments. 
--- a/ipython-tut.txt	Tue May 04 17:21:12 2010 +0530
+++ b/ipython-tut.txt	Wed May 05 17:31:32 2010 +0530
@@ -1,7 +1,9 @@
 Hello friends and welcome to this tutorial on IPython and its features. IPython
 is an enhanced interactive Python interpreter. IPython provides various advanced
-features that the vanilla Python interpreter does not. We have shown some of these
-features in the previous tutorials. In this tutorial we shall look at a few more
-of them.
+features that the vanilla Python interpreter does not. We have seen some of these
+features in the previous tutorials. In this tutorial we shall recall them and 
+look at a few more new ones.
 
 
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/presentations/functions.tex	Wed May 05 17:31:32 2010 +0530
@@ -0,0 +1,138 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%Tutorial slides on Python.
+%
+% Author: FOSSEE 
+% Copyright (c) 2009, FOSSEE, IIT Bombay
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\documentclass[14pt,compress]{beamer}
+%\documentclass[draft]{beamer}
+%\documentclass[compress,handout]{beamer}
+%\usepackage{pgfpages} 
+%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
+
+% Modified from: generic-ornate-15min-45min.de.tex
+\mode<presentation>
+{
+  \usetheme{Warsaw}
+  \useoutertheme{infolines}
+  \setbeamercovered{transparent}
+}
+
+\usepackage[english]{babel}
+\usepackage[latin1]{inputenc}
+%\usepackage{times}
+\usepackage[T1]{fontenc}
+
+% Taken from Fernando's slides.
+\usepackage{ae,aecompl}
+\usepackage{mathpazo,courier,euler}
+\usepackage[scaled=.95]{helvet}
+
+\definecolor{darkgreen}{rgb}{0,0.5,0}
+
+\usepackage{listings}
+\lstset{language=Python,
+    basicstyle=\ttfamily\bfseries,
+    commentstyle=\color{red}\itshape,
+  stringstyle=\color{darkgreen},
+  showstringspaces=false,
+  keywordstyle=\color{blue}\bfseries}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Macros
+\setbeamercolor{emphbar}{bg=blue!20, fg=black}
+\newcommand{\emphbar}[1]
+{\begin{beamercolorbox}[rounded=true]{emphbar} 
+      {#1}
+ \end{beamercolorbox}
+}
+\newcounter{time}
+\setcounter{time}{0}
+\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
+
+\newcommand{\typ}[1]{\lstinline{#1}}
+
+\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
+
+% Title page
+\title{Python for Scientific Computing : Functions}
+
+\author[FOSSEE] {FOSSEE}
+
+\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
+\date{}
+
+% DOCUMENT STARTS
+\begin{document}
+
+\begin{frame}
+  \titlepage
+\end{frame}
+
+\begin{frame}
+  \frametitle{About the Session}
+  \begin{block}{Functions in Python}
+    \begin{itemize}
+    \item Function definition
+    \item Function call
+    \end{itemize}
+  \end{block}
+\end{frame}
+
+\begin{frame}[fragile]
+  \frametitle{Functions: default arguments}
+  \begin{lstlisting}
+In []: greet = 'hello world'
+
+In []: greet.split()
+Out[]: ['hello', 'world']
+
+In []: line = 'Rossum, Guido, 54, 46, 55'
+
+In []: line.split(',')
+Out[]: ['Rossum', ' Guido', ' 54',
+                        ' 46', ' 55']
+  \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+  \frametitle{Functions: Keyword arguments}
+We have seen the following
+\begin{lstlisting}
+legend(['sin(2y)'], loc = 'center')
+
+plot(y, sin(y), 'g', linewidth = 2)
+
+annotate('local max', xy = (1.5, 1))
+
+pie(science.values(), 
+            labels = science.keys())
+  \end{lstlisting}
+\end{frame}
+
+\begin{frame}
+  \frametitle{Summary}
+  \begin{itemize}
+      \item The \typ{def} keyword
+      \item Docstrings
+      \item Function arguments
+        \begin{itemize}
+        \item Default arguments
+        \item Keyword arguments
+        \end{itemize}
+      \item Return values
+  \end{itemize}
+\end{frame}
+
+\begin{frame}
+  \frametitle{Thank you!}  
+  \begin{block}{}
+  This session is part of \textcolor{blue}{FOSSEE} project funded by:
+  \begin{center}
+    \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
+  \end{center}  
+  \end{block}
+\end{frame}
+
+\end{document}