associação pythonbrasil[11] django zope/plone planet Início Logado como (Entrar)

attachment:Introdução a Python - GrupySP (30_05_2008).tex de GustavoScalet

Arquivo anexado 'Introdução a Python - GrupySP (30_05_2008).tex'

Download

   1 \documentclass{beamer}
   2 \usepackage[utf8]{inputenc}
   3 \usepackage{lmodern}
   4 \usepackage[T1]{fontenc}
   5 \usepackage{listings}
   6 \usepackage{multicol}
   7 
   8 \usetheme{Dresden}
   9 %\usecolortheme{beaver}
  10 
  11 \author{Gustavo Serra Scalet \texttt{gsscalet@gmail.com}}
  12 \title{Introdução a Python}
  13 \institute{Encontros GrupySP}
  14 \date{30 de Maio, 2008}
  15 
  16 \setbeamercolor{item}{fg=blue}
  17 \definecolor{DarkBlue}{rgb}{0.0, 0.35, 0.5}
  18 \setbeamercolor{structure}{fg=DarkBlue}
  19 \AtBeginSection[]{
  20   \begin{frame}
  21     \frametitle{Roadmap}
  22     \tableofcontents[currentsection]
  23   \end{frame}
  24 }
  25 
  26 
  27 \begin{document}
  28 
  29  % Para colorir o código Python peguei de:
  30  % http://www.gustavobarbieri.com.br/python/aulas_python/resumo.tex
  31   \lstset{
  32     frame=single,
  33     showstringspaces=false,  
  34     extendedchars=true,
  35     language=Python,
  36     backgroundcolor=\color[rgb]{0.95,0.95,0.95},
  37     rulecolor=\color[rgb]{0.3,0.3,0.3},
  38     basicstyle=\scriptsize\ttfamily,
  39     commentstyle=\color[rgb]{0.5,0.0,0.0}\rmfamily\itshape,
  40     keywordstyle=\color[rgb]{0.7,0.0,0.8}\bfseries,
  41     stringstyle=\color[rgb]{0.6,0.4,0.4},
  42     identifierstyle=\color[rgb]{0.2,0.2,0.9}
  43  }
  44 
  45 \begin{frame}[fragile]
  46   \titlepage
  47 \end{frame}
  48 
  49 \section{Introdução}
  50 \begin{frame}
  51 \frametitle{Um pouco da história e futuro}
  52 \begin{itemize}
  53   \item Criada por Guido van Rossum na Holanda para ser um sucessor de uma linguagem chamada ABC
  54   \item O nome Python veio de "Monty Python's Flying Circus", que Guido van Rossum estava lendo durante a implementação. Ele precisava de um nome curto, único e levemente misterioso.
  55   \item Surgiu em torno dos anos 90 e após 2001, já na sua versão 2.0, python tem sua própria licença compatível com a GPL com a criação da PSF (Python Software Foundation)
  56   \item Python está na versão 2.6 e há desenvolvimento de uma versão 3.0 com diversas alterações
  57   \item Última versão (08/05/2008): 2.6alpha3 e 3.0alpha5
  58 \end{itemize}
  59 \end{frame}
  60 
  61 \begin{frame}
  62 \frametitle{E o que Python tem de tão especial?}
  63 \begin{itemize}
  64   \item É livre!!
  65   \item Multiplataforma (roda em Windows, Linux/Unix, OS/2, Mac, .Net e S60...)
  66   \item Multiparadigma (Estrutural, orientada a objetos, funcional)
  67   \item É interpretada
  68   \item Linguagem limpa, com sintaxe legível e de fácil aprendizado
  69   \item Gerenciamento automático de memória: Esqueça os frees!
  70   \item Nível altíssimo de tipos de dados dinâmicos
  71   \item Extensas bibliotecas por padrão e muitos módulos \textit{third party} para praticamente qualquer tarefa
  72   \item Usada como linguagem de scripts por diversos sistemas (GIMP, Blender)
  73 \end{itemize}
  74 \end{frame}
  75 
  76 \begin{frame}
  77 \frametitle{Algumas aplicações e bibliotecas externas}
  78 
  79 \begin{multicols}{2}{
  80   \begin{itemize}
  81     \item \scriptsize Web
  82     \begin{itemize}
  83       \item \scriptsize Frameworks (Django, TurboGears)
  84       \item Servidor de aplicações (Zope)
  85       \item Sistemas de gerenciamentos (Plone)
  86       \item Suporte a diversos protocolos (CGI, http, ftp, smtp)
  87     \end{itemize}
  88     \item Graphic User Interface (GUI)
  89     \begin{itemize}
  90       \item \scriptsize Tk (comum em muitos portes do python)
  91       \item wxWidgets
  92       \item GTK+
  93       \item Qt
  94       \item Microsoft Foundation Classes
  95       \item Delphi
  96     \end{itemize}
  97     \item Banco de Dados
  98     \begin{itemize}
  99       \item \scriptsize MySQL
 100       \item Oracle
 101       \item MS SQL Server
 102       \item PostgreSQL
 103       \item SybODBC
 104       \item SQLite
 105     \end{itemize}
 106     \item Científico e numérico
 107     \begin{itemize}
 108       \item \scriptsize Processamento de imagens (VTK, PIL)
 109       \item Cálculos e precisos (SciPy, NumPy, GmPy)
 110     \end{itemize}
 111     \item Jogos
 112     \begin{itemize}
 113       \item \scriptsize Pygame
 114       \item PyOpenGL
 115     \end{itemize}
 116     \item Entre muitos outros...
 117   \end{itemize}
 118 }
 119 \end{multicols}
 120 \end{frame}
 121 
 122 \begin{frame}
 123 \frametitle{O que dizem por aí...}
 124   \begin{itemize}
 125     \item "Python é nos permite produzir novas funcionalidades em tempo recorde com o mínimo de desenvolvedores" - Cuong Do, Arquiteto de software, YouTube.com.
 126     \item "Python foi importante para o Google desde o seu início, permanecendo até hoje. Muitos de nossos engenheiros usam Python e nós estamos procurando mais pessoas com habilidades nessa linguagem." - Peter Norvig, Diretor de qualidade de busca, Google, Inc.
 127     \item "Nós ensinamos Python para estudantes da graduação e da pós em nossos cursos de semânticas Web simplesmente porque não há nada tão flexível e com tantas bibliotecas web." - Prof. James A. Hendler, University of Maryland
 128   \end{itemize}
 129   \begin{footnotesize}
 130     Tradução livre de \url{http://www.python.org/about/quotes/}
 131   \end{footnotesize}
 132 \end{frame}
 133 
 134 \section{Tipos de dados}
 135 \begin{frame}
 136 \frametitle{Apresentando os tipos}
 137 Em python podemos separar os tipos de dados nativos em dois grandes grupos:
 138 \pause
 139 \begin{enumerate}
 140  \item \textbf{Imutáveis} - Inteiros, inteiros longos, pontos flutuantes, complexos, strings e tuplas
 141 \pause
 142  \item \textbf{Mutáveis} - Listas e dicionários
 143 \end{enumerate}
 144 \pause
 145 Fora eles tem o None, que seria um NULL. \\
 146 \pause
 147 Mas qual a diferença entre esses mutáveis e imutáveis?
 148 \end{frame}
 149 
 150 \begin{frame}[containsverbatim]
 151 \frametitle{Mutáveis e imutáveis?!}
 152 Analisando um tipo imutável (no caso string) vemos que:
 153  \begin{lstlisting}
 154 >>> str = "Gustavo"
 155 >>> str2 = str
 156 >>> str = str + " Serra"
 157 >>> str
 158 'Gustavo Serra'
 159 >>> str2
 160 'Gustavo'
 161  \end{lstlisting}
 162 Isso acontece porque a ao incrementarmos a \texttt{str} com \texttt{" Serra"} um novo objeto foi criado, e apenas \texttt{str} apontava para ele, enquanto que \texttt{str2} apontava para o objeto antigo
 163 \end{frame}
 164 
 165 \begin{frame}[containsverbatim]
 166 \frametitle{Mutáveis e imutáveis?!}
 167 Mas se fosse um tipo imutável (listas):
 168  \begin{lstlisting}
 169 >>> lista = ['abacaxi',(0,0),2]
 170 >>> lista2 = lista
 171 >>> lista.append('Novo Elemento')
 172 >>> lista
 173 ['abacaxi', (0, 0), 2, 'Novo Elemento']
 174 >>> lista2
 175 ['abacaxi', (0, 0), 2, 'Novo Elemento']
 176  \end{lstlisting}
 177 Como o tipo lista pode se modificar, ele foi alterado e não recriado como outro objeto, sendo assim a lista2 e lista apontam para o mesmo objeto mesmo após a sua alteração
 178 \end{frame}
 179 
 180 \section{O Interpretador}
 181 \begin{frame}[containsverbatim]
 182 \frametitle{Seu melhor amigo}
 183 Use como calculadora, peça ajuda, pergunte métodos de objetos, teste trechos de códigos, recrie ambientes... use e abuse!
 184  \begin{lstlisting}
 185 [21:10:31] gut@quasar ~ $ python
 186 Python 2.4.4 (#1, Apr  6 2008, 07:48:32)
 187 [GCC 4.1.2 (Gentoo 4.1.2 p1.0.2)] on linux2
 188 Type "help", "copyright", "credits" or "license" for more information.
 189 >>>
 190  \end{lstlisting}
 191 \end{frame}
 192 
 193 \section{Sintaxe}
 194 \begin{frame}[containsverbatim]
 195 \frametitle{Um erro incomum}
 196 Python é orientado a indentação, o que quer dizer que um código indentado não é só elegante mas também é necessário para o reconhecimento dos laços.
 197  \begin{lstlisting}
 198 >>> if 1 == 2:
 199 ...     print "Temos problemas..."
 200 ...     print "...dos grandes!"
 201 ...  else:
 202   File "<stdin>", line 3
 203     else:
 204         ^
 205 IndentationError: unindent does not match any outer indentation level
 206 >>>
 207  \end{lstlisting}
 208 \end{frame}
 209 
 210 \begin{frame}[containsverbatim]
 211 \frametitle{Exemplo simples}
 212 Vendo quais elementos são iguais em duas listas
 213  \begin{lstlisting}
 214 >>> l = [1,2,3,4,5]
 215 >>> p = [3,4,5,6,7]
 216 >>> for x in l:
 217 ...  if x in p:
 218 ...   print x,
 219 ...
 220 3 4 5
 221  \end{lstlisting}
 222 \end{frame}
 223 
 224 \begin{frame}[containsverbatim]
 225 \frametitle{Melhorando...}
 226 Usando conjuntos!
 227  \begin{lstlisting}
 228 >>> l = set([1,2,3,4,5])
 229 >>> p = set([3,4,5,6,7])
 230 >>> l & p  # '&' eh o operador logico AND
 231 set([3, 4, 5])
 232  \end{lstlisting}
 233 \end{frame}
 234 
 235 \begin{frame}[containsverbatim]
 236 \frametitle{Deixando mais pythônico}
 237  \begin{lstlisting}
 238 >>> l = [1,2,3,4,5]
 239 >>> p = [3,4,5,6,7]
 240 >>> [x for x in l if x not in p]
 241 [1, 2]
 242  \end{lstlisting}
 243 Por que os programadores tentam fazer tudo em uma linha?!
 244 \end{frame}
 245 
 246 \begin{frame}[containsverbatim]
 247 \frametitle{Padronizações}
 248 É costume incluir nos cabeçalhos de seus programas as seguintes linhas:
 249  \begin{lstlisting}
 250 #!/usr/bin/env python
 251 # -*- coding: utf-8 -*-
 252  \end{lstlisting}
 253 É também uma boa maneira não interpretar seu código diretamente:
 254  \begin{lstlisting}
 255 def main():
 256     # Agora sim! Programe aqui dentro
 257     ...
 258 
 259 if __name__ == "__main__":
 260     main()
 261  \end{lstlisting}
 262 Deste jeito seu código fica muito mais modularizado
 263 \end{frame}
 264 
 265 \begin{frame}
 266 \frametitle{Palavras chaves}
 267 Explore-as! Há muitos poder nelas
 268   \begin{center}
 269   % use packages: array
 270     \begin{tabular}{lllll}
 271     and & del & from & not & while \\
 272     as & elif & global & or & with \\
 273     assert & else & if & pass & yield \\
 274     break & except & import & print \\
 275     class & exec & in & raise \\
 276     continue & finally & is & return \\
 277     def & for & lambda & try \\
 278     \end{tabular}
 279   \end{center}
 280 \end{frame}
 281 
 282 \begin{frame}[containsverbatim]
 283 \frametitle{Python tem até easter egg!}
 284   \begin{scriptsize}
 285     Use o módulo \texttt{this}:
 286   \end{scriptsize}
 287   \begin{lstlisting}
 288 >>> import this
 289   \end{lstlisting}
 290   \begin{scriptsize}
 291     The Zen of Python, by Tim Peters
 292   \end{scriptsize}\\
 293   \begin{tiny}
 294     Beautiful is better than ugly.\\
 295     Explicit is better than implicit.\\
 296     Simple is better than complex.\\
 297     Complex is better than complicated.\\
 298     Flat is better than nested.\\
 299     Sparse is better than dense.\\
 300     Readability counts.\\
 301     Special cases aren't special enough to break the rules.\\
 302     Although practicality beats purity.\\
 303     Errors should never pass silently.\\
 304     Unless explicitly silenced.\\
 305     In the face of ambiguity, refuse the temptation to guess.\\
 306     There should be one-- and preferably only one --obvious way to do it.\\
 307     Although that way may not be obvious at first unless you're Dutch.\\
 308     Now is better than never.\\
 309     Although never is often better than *right* now.\\
 310     If the implementation is hard to explain, it's a bad idea.\\
 311     If the implementation is easy to explain, it may be a good idea.\\
 312     Namespaces are one honking great idea -- let's do more of those!\\
 313   \end{tiny}
 314 \end{frame}
 315 
 316 \section{Referências}
 317 \begin{frame}
 318   \frametitle{Referências}
 319 
 320 
 321 \begin{enumerate}
 322   \begin{footnotesize}
 323     \item \url{http://www.python.org/}
 324     \item \url{http://www.gustavobarbieri.com.br/python/aulas_python/}
 325     \item \url{http://www.dmat.furg.br/~python/aspectos.html}
 326   \end{footnotesize}
 327 \end{enumerate}
 328 
 329 Aprenda Mais!
 330 \begin{itemize}
 331   \begin{footnotesize}
 332     \item \url{http://www.pythonbrasil.com.br/moin.cgi/DocumentacaoPython}
 333     \item \url{http://www.pythonbrasil.com.br/moin.cgi/CookBook}
 334     \item \url{http://docs.python.org/}
 335   \end{footnotesize}
 336 \end{itemize}
 337 \end{frame}
 338 
 339 \end{document}
 340 

Arquivos Anexados

Para se referir aos anexos de uma página, use attachment:filename, como mostrado abaixo na lista de arquivos. NÃO use a URL do link [get], já que a mesma está sujeita a alterações, e pode facilmente se tonar inválida.
  • [obter | ver] (2013-01-12 01:34:31, 429.0 KB) [[attachment:Introdução a Python - GrupySP (30_05_2008).pdf]]
  • [obter | ver] (2013-01-12 01:34:31, 10.5 KB) [[attachment:Introdução a Python - GrupySP (30_05_2008).tex]]
 Todos os arquivos | Arquivos Selecionados: excluir mover para página

Você não tem permissão para anexar arquivos a esta página.