day2/cheatsheet3.tex
changeset 301 49bdffe4dca5
child 327 c78cad28c2f7
equal deleted inserted replaced
300:f87f2a310abe 301:49bdffe4dca5
       
     1 \documentclass[12pt]{article}
       
     2 
       
     3 
       
     4 \title{Python: Data Structures}
       
     5 \author{FOSSEE}
       
     6 \usepackage{listings}
       
     7 \lstset{language=Python,
       
     8     basicstyle=\ttfamily,
       
     9 commentstyle=\itshape\bfseries, 
       
    10 showstringspaces=false
       
    11 }
       
    12 \newcommand{\typ}[1]{\lstinline{#1}}
       
    13 \usepackage[english]{babel}
       
    14 \usepackage[latin1]{inputenc}
       
    15 \usepackage{times}
       
    16 \usepackage[T1]{fontenc}
       
    17 \usepackage{ae,aecompl}
       
    18 \usepackage{mathpazo,courier,euler}
       
    19 \usepackage[scaled=.95]{helvet}
       
    20 
       
    21 \begin{document}
       
    22 \date{}
       
    23 \vspace{-1in}
       
    24 \begin{center}
       
    25 \LARGE{Python: Functions and Objects}\\
       
    26 \large{FOSSEE}
       
    27 \end{center}
       
    28 \section{Functions}
       
    29 Function definition
       
    30   \begin{lstlisting}
       
    31 def signum( r ):    
       
    32     if r < 0:
       
    33         return -1
       
    34     elif r > 0:
       
    35         return 1
       
    36     else:
       
    37         return 0
       
    38   \end{lstlisting}
       
    39 Default Arguments 
       
    40 \begin{lstlisting}
       
    41 def welcome(greet, name='world!'):
       
    42     print greet, name
       
    43 \end{lstlisting}
       
    44 Keyword Arguments
       
    45 \begin{lstlisting}
       
    46 In []: plot(y, sin(y), 'g', linewidth=2)
       
    47 \end{lstlisting}
       
    48 Self contained python script
       
    49   \begin{lstlisting}
       
    50 from scipy import linspace, pi, sin
       
    51 from pylab import plot, legend, annotate
       
    52 from pylab import xlim, ylim
       
    53 
       
    54 x = linspace(-5*pi, 5*pi, 500)
       
    55 plot(x, x, 'b')
       
    56 plot(x, -x, 'b')
       
    57 plot(x, sin(x), 'g', linewidth=2)
       
    58 plot(x, x*sin(x), 'r', linewidth=3)
       
    59 legend(['x', '-x', 'sin(x)', 'xsin(x)'])
       
    60 annotate('origin', xy = (0, 0))
       
    61 xlim(-5*pi, 5*pi)
       
    62 ylim(-5*pi, 5*pi)
       
    63   \end{lstlisting}
       
    64 
       
    65 \end{document}