diff options
-rw-r--r-- | basic-data-type/quickref.tex | 49 | ||||
-rw-r--r-- | basic-data-type/script.rst (renamed from basicdatatype.rst) | 90 | ||||
-rw-r--r-- | basic-data-type/slides.tex | 158 | ||||
-rw-r--r-- | getting-started-with-lists/getting_started_with_lists.rst | 137 | ||||
-rw-r--r-- | getting-started-with-lists/quickref.tex | 8 | ||||
-rw-r--r-- | getting-started-with-lists/slides.tex | 106 |
6 files changed, 534 insertions, 14 deletions
diff --git a/basic-data-type/quickref.tex b/basic-data-type/quickref.tex new file mode 100644 index 0000000..1047219 --- /dev/null +++ b/basic-data-type/quickref.tex @@ -0,0 +1,49 @@ +\documentclass{article} +\begin{Document} +\begin{center} +\textbf{Basic DataType Quick Reference}\\ +\end{center} +Declaring an Integer:\\ +{\ex \lstinline| b=9999999999999999999 |} + +Declaring a float:\\ +{\ex \lstinline| p=3.141592 |} + +Declaring a Complex number:\\ +{\ex \lstinline| c = 3.2+4.6j |} + +Modulo Operator:\\ +{\ex \lstinline| 87 % 6 |} + +Exponent Operator:\\ +{\ex \lstinline| 7**8 |} + +Declaring a list:\\ +{\ex \lstinline| var_list = [1, 1.2, [1,2]] |} + +Declaring a string:\\ +{\ex \lstinline| k='Single quote' |} +{\ex \lstinline| l="Double quote contain's single quote" |} +{\ex \lstinline| m='''"Contain's both"''' |} + +Declaring a tuple:\\ +{\ex \lstinline| var_tup = (1,2,3,4) |} + + +Accessing Lists, string and tuples:\\ +{\ex \lstinline| seq[-1] |} + +Interconversion of number datatype:\\ +{\ex \lstinline| float(2.3+4.2j) |} + + +Interconversion of sequences:\\ +{\ex \lstinline| tup=tuple([1,2,3,4,5]) |} + +Spliting string into lists:\\ +{\ex \lstinline| ''split this sting''.split() |} + +Join lists to create strings:\\ +{\ex \lstinline| ','.join['List','joined','on','commas'] |} + +\end{Document} diff --git a/basicdatatype.rst b/basic-data-type/script.rst index ed97c24..64583c7 100644 --- a/basicdatatype.rst +++ b/basic-data-type/script.rst @@ -1,14 +1,29 @@ -Hello friends and welcome to the tutorial on Basic Data types and -operators in Python. +.. Objectives +.. ---------- + +.. Learn about Python Data Structures and Operators.(Remembering) +.. Use them to do basic operations.(Applying) + +.. Prerequisites +.. ------------- + + + +.. Author : Amit Sethi + 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. {{{ Show the slide containing title }}} {{{ Show the slide containing the outline slide }}} In this tutorial, we shall look at:: - * Various Datatypes in Python - * Operators with a little hands-on on how they can be applied to - the different data types. + * Datatypes in Python + * Operators in Python + +with a little hands-on on how they can be applied to the different data types. @@ -20,8 +35,8 @@ There are three built-in data types in python to represent numbers. These are: * Integers - * Complex and - * Boolean + * float and + * Complex Lets first talk about integers. :: @@ -81,7 +96,7 @@ 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 define by j notation instead of i. Complex numbers have a lot of functions specific to them. +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> @@ -97,6 +112,10 @@ We can get the absolute value using the function :: abs(c) + + +{{ Slide for memory aid }} + Python also has Boolean as a built-in type. Try it out just type :: @@ -142,10 +161,42 @@ where as the expression :: gives the value False. -Lets now discuss sequence data structures in python. Sequence + +Lets now look at some operators available in Python to manipulate these data types. + + + +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`. :: + + a=73 + a*=34 + +is same as :: + + a=a*34 + +and :: + + a/=23 + +is same as :: + + 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. + {{{ slide to for memory aid }}} The sequence datatypes in python are :: @@ -207,7 +258,7 @@ unlike '[' for lists.:: Because of their sequential property there are certain functions and operations we can apply to all of them. -{{{ Slide for memory aid }}} + The first one is accessing. @@ -382,6 +433,21 @@ Thus we get a list joined on commas. Similarly we can do spaces.:: Note that the list has to be a list of strings to apply join operation. +With this we come to the end of this tutorial . + +In this tutorial we have discussed + +1. Number Datatypes , integer,float and complex +2. Boolean and datatype and operators +3. Sequence data types ,List,String and Tuple +4. Accesing sequence +5. Slicing sequences +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. @@ -399,7 +465,3 @@ Thank You. -Author : Amit Sethi -Internal Reviewer 1 : Nishanth -Internal Reviewer 2 : -External Reviewer diff --git a/basic-data-type/slides.tex b/basic-data-type/slides.tex new file mode 100644 index 0000000..b66f55d --- /dev/null +++ b/basic-data-type/slides.tex @@ -0,0 +1,158 @@ +% Created 2010-10-13 Wed 17:08 +\documentclass[presentation]{beamer} +\usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{graphicx} +\usepackage{longtable} +\usepackage{float} +\usepackage{wrapfig} +\usepackage{soul} +\usepackage{amssymb} +\usepackage{hyperref} + + +\title{Plotting Data } +\author{FOSSEE} +\date{2010-09-14 Tue} + +\begin{document} + +\maketitle + + + + + + +\begin{frame} +\frametitle{Tutorial Plan} +\label{sec-1} +\begin{itemize} + +\item Datatypes in Python\\ +\label{sec-1.1}% +\item Operators in Python\\ +\label{sec-1.2}% +\end{itemize} % ends low level +\end{frame} +\begin{frame} +\frametitle{Numbers} +\label{sec-2} +\begin{itemize} + +\item Integers\\ +\label{sec-2.1}% +\item Float\\ +\label{sec-2.2}% +\item Complex\\ +\label{sec-2.3}% +\end{itemize} % ends low level +\end{frame} +\begin{frame} +\frametitle{Boolean} +\label{sec-3} +\begin{itemize} + +\item True\\ +\label{sec-3.1}% +\item False\\ +\label{sec-3.2}% +\end{itemize} % ends low level +\end{frame} +\begin{frame} +\frametitle{Sequence Data types} +\label{sec-4} +\begin{itemize} + +\item Data in Sequence\\ +\label{sec-4.1}% +\item Accessed using Index +\label{sec-4.2}% +\begin{itemize} + +\item list\\ +\label{sec-4.2.1}% +\item String\\ +\label{sec-4.2.2}% +\item Tuple\\ +\label{sec-4.2.3}% +\end{itemize} % ends low level +\end{itemize} % ends low level +\end{frame} +\begin{frame} +\frametitle{All are Strings} +\label{sec-5} +\begin{itemize} + +\item k='Single quote'\\ +\label{sec-5.1}% +\item l="Double quote contain's single quote"\\ +\label{sec-5.2}% +\item m='''"Contain's both"'''\\ +\label{sec-5.3}% +\end{itemize} % ends low level +\end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-6} +\begin{itemize} + +\item a=73\\ +\label{sec-6.1}% +\item b=3.14\\ +\label{sec-6.2}% +\item c=3+4j\\ +\label{sec-6.3}% +\end{itemize} % ends low level +\end{frame} +\begin{frame} +\frametitle{Summary Contd.} +\label{sec-7} +\begin{itemize} + +\item t=True\\ +\label{sec-7.1}% +\item f=False\\ +\label{sec-7.2}% +\item t and f\\ +\label{sec-7.3}% +\end{itemize} % ends low level +\end{frame} +\begin{frame} +\frametitle{Summary Contd.} +\label{sec-8} +\begin{itemize} + +\item l= [2,1,4,3]\\ +\label{sec-8.1}% +\item s='hello'\\ +\label{sec-8.2}% +\item tu=(1,2,3,4)\\ +\label{sec-8.3}% +\end{itemize} % ends low level +\end{frame} +\begin{frame} +\frametitle{Summary Contd.} +\label{sec-9} +\begin{itemize} + +\item tu[-1]\\ +\label{sec-9.1}% +\item s[1:-1]\\ +\label{sec-9.2}% +\end{itemize} % ends low level +\end{frame} +\begin{frame} +\frametitle{Summary Contd.} +\label{sec-10} +\begin{itemize} + +\item Sorted(l)\\ +\label{sec-10.1}% +\item reversed(s)\\ +\label{sec-10.2}% +\end{itemize} % ends low level +\end{frame} + +\end{document} diff --git a/getting-started-with-lists/getting_started_with_lists.rst b/getting-started-with-lists/getting_started_with_lists.rst new file mode 100644 index 0000000..a82de02 --- /dev/null +++ b/getting-started-with-lists/getting_started_with_lists.rst @@ -0,0 +1,137 @@ +Hello friends and welcome to the tutorial on getting started with +lists. + + {{{ Show the slide containing title }}} + + {{{ Show the slide containing the outline slide }}} + +In this tutorial we will be getting acquainted with a python data +structure called lists. We will learn :: + + * How to create lists + * Structure of lists + * Access list elements + * Append elements to lists + * Deleting elements from lists + +List is a compound data type, it can contain data of other data +types. List is also a sequence data type, all the elements are in +order and there order has a meaning. + +We will first create an empty list with no elements. On your IPython +shell type :: + + empty = [] + type(empty) + + +This is an empty list without any elements. + +* Filled lists + +Lets now define a list, nonempty and fill it with some random elements. + +nonempty = ['spam', 'eggs', 100, 1.234] + +Thus the simplest way of creating a list is typing out a sequence +of comma-separated values (items) between square brackets. +All the list items need not have the same data type. + + + +As we can see lists can contain different kinds of data. In the +previous example 'spam' and 'eggs' are strings and 100 and 1.234 +integer and float. Thus we can put elements of heterogenous types in +lists. Thus list themselves can be one of the element types possible +in lists. Thus lists can also contain other lists. Example :: + + list_in_list=[[4,2,3,4],'and', 1, 2, 3, 4] + +We access list elements using the number of index. The +index begins from 0. So for list nonempty, nonempty[0] gives the +first element, nonempty[1] the second element and so on and +nonempty[3] the last element. :: + + nonempty[0] + nonempty[1] + nonempty[3] + +We can also access the elememts from the end using negative indices :: + + nonempty[-1] + nonempty[-2] + nonempty[-4] + +-1 gives the last element which is the 4th element , -2 second to last and -4 gives the fourth +from last element which is first element. + +We can append elements to the end of a list using append command. :: + + nonempty.append('onemore') + nonempty + nonempty.append(6) + nonempty + +As we can see non empty appends 'onemore' and 6 at the end. + + + +Using len function we can check the number of elements in the list +nonempty. In this case it being 6 :: + + len(nonempty) + + + +Just like we can append elements to a list we can also remove them. +There are two ways of doing it. One is by using index. :: + + del(nonempty[1]) + + + +deletes the element at index 1, i.e the second element of the +list, 'eggs'. The other way is removing element by content. Lets say +one wishes to delete 100 from nonempty list the syntax of the command +should be :: + + a.remove(100) + +but what if their were two 100's. To check that lets do a small +experiment. :: + + a.append('spam') + a + a.remove('spam') + a + +If we check a now we will see that the first occurence 'spam' is removed +thus remove removes the first occurence of the element in the sequence +and leaves others untouched. + + +{{{Slide for Summary }}} + + +In this tutorial we came across a sequence data type called lists. :: + + * We learned how to create lists. + * How to access lists. + * Append elements to list. + * Delete Element from list. + * And Checking list length. + + + +{{{ Sponsored by Fossee Slide }}} + +This tutorial was created as a part of FOSSEE project. + +I hope you found this tutorial useful. + +Thank You + + + * Author : Amit Sethi + * First Reviewer : + * Second Reviewer : Nishanth diff --git a/getting-started-with-lists/quickref.tex b/getting-started-with-lists/quickref.tex new file mode 100644 index 0000000..b26d168 --- /dev/null +++ b/getting-started-with-lists/quickref.tex @@ -0,0 +1,8 @@ +Creating a linear array:\\ +{\ex \lstinline| x = linspace(0, 2*pi, 50)|} + +Plotting two variables:\\ +{\ex \lstinline| plot(x, sin(x))|} + +Plotting two lists of equal length x, y:\\ +{\ex \lstinline| plot(x, y)|} diff --git a/getting-started-with-lists/slides.tex b/getting-started-with-lists/slides.tex new file mode 100644 index 0000000..df1462c --- /dev/null +++ b/getting-started-with-lists/slides.tex @@ -0,0 +1,106 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%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} + +\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{Your Title Here} + +\author[FOSSEE] {FOSSEE} + +\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} +\date{} + +% DOCUMENT STARTS +\begin{document} + +\begin{frame} + \maketitle +\end{frame} + +\begin{frame}[fragile] + \frametitle{Outline} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% All other slides here. %% +%% The same slides will be used in a classroom setting. %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\begin{frame}[fragile] + \frametitle{Summary} + \begin{itemize} + \item + \end{itemize} +\end{frame} + +\begin{frame} + \frametitle{Thank you!} + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +\end{frame} + +\end{document} |