summaryrefslogtreecommitdiff
path: root/day2/cheatsheet3.tex
blob: 8f5a6f16a69263d64c2e8da9916e83137a000b89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
\documentclass[12pt]{article}


\title{Python: Data Structures}
\author{FOSSEE}
\usepackage{listings}
\lstset{language=Python,
    basicstyle=\ttfamily,
commentstyle=\itshape\bfseries, 
showstringspaces=false
}
\newcommand{\typ}[1]{\lstinline{#1}}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{ae,aecompl}
\usepackage{mathpazo,courier,euler}
\usepackage[scaled=.95]{helvet}

\begin{document}
\date{}
\vspace{-1in}
\begin{center}
\LARGE{Python: Functions and Objects}\\
\large{FOSSEE}
\end{center}
\section{Functions}
Function definition
  \begin{lstlisting}
def signum( r ):    
    if r < 0:
        return -1
    elif r > 0:
        return 1
    else:
        return 0
  \end{lstlisting}
Default Arguments 
\begin{lstlisting}
def welcome(greet, name='world!'):
    print greet, name
\end{lstlisting}
Keyword Arguments
\begin{lstlisting}
In []: plot(y, sin(y), 'g', linewidth=2)
\end{lstlisting}
Self contained python script
  \begin{lstlisting}
from scipy import linspace, pi, sin
from pylab import plot, legend, annotate
from pylab import xlim, ylim

x = linspace(-5*pi, 5*pi, 500)
plot(x, x, 'b')
plot(x, -x, 'b')
plot(x, sin(x), 'g', linewidth=2)
plot(x, x*sin(x), 'r', linewidth=3)
legend(['x', '-x', 'sin(x)', 'xsin(x)'])
annotate('origin', xy = (0, 0))
xlim(-5*pi, 5*pi)
ylim(-5*pi, 5*pi)
  \end{lstlisting}

\end{document}