diff options
author | Prabhu Ramachandran | 2017-11-17 23:03:18 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2017-11-17 23:03:18 +0530 |
commit | b64d87addfc4b90e3a2c93763eff8faf1e7cee21 (patch) | |
tree | 6cacdbfbebdb120ce3cc1c4a86453d635038f49d /advanced_python/only_kwargs.tex | |
parent | 3b7ed43d8d159470654351c31a52f9edeaeaa60c (diff) | |
download | python-workshops-b64d87addfc4b90e3a2c93763eff8faf1e7cee21.tar.gz python-workshops-b64d87addfc4b90e3a2c93763eff8faf1e7cee21.tar.bz2 python-workshops-b64d87addfc4b90e3a2c93763eff8faf1e7cee21.zip |
Rename the files for easier navigation.
Diffstat (limited to 'advanced_python/only_kwargs.tex')
-rw-r--r-- | advanced_python/only_kwargs.tex | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/advanced_python/only_kwargs.tex b/advanced_python/only_kwargs.tex deleted file mode 100644 index 8d4caef..0000000 --- a/advanced_python/only_kwargs.tex +++ /dev/null @@ -1,95 +0,0 @@ -\documentclass[14pt,compress,aspectratio=169]{beamer} - -\input{macros.tex} - -\title[only kwargs]{Advanced Python} -\subtitle{Keyword-only arguments} - -\author[FOSSEE] {The FOSSEE Group} - -\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {Mumbai, India} - -\begin{document} - -\begin{frame} - \titlepage -\end{frame} - -\begin{frame}[fragile, plain] - \frametitle{Motivation} - \vspace*{-0.1in} - \begin{itemize} - \item One can mix positional and keyword arguments - \end{itemize} - \begin{lstlisting} -In []: def f(a, b=2): - ...: print(a, b) - -In []: f(a=2, b=3) -2 3 - -In []: f(b=2, a=3) -3 2 - -In []: f(10, 20) -1 2 -\end{lstlisting} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Motivation} - \begin{itemize} - \item Function changes: positional arguments change in order or number - \item Accidentally passing an extra argument - \item Can we have purely keyword arguments? - - \vspace*{0.5in} - \item Yes, in Python 3.x! - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Keyword-only arguments} - \begin{lstlisting} -In []: def f(a, *args, b=False): - ...: print(a, args, b) - -In []: f(1, 20) -1 (20,) False - -In []: f(1, b=20) -1 () 20 -\end{lstlisting} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Keyword-only arguments} - \noindent Without any extra arguments: -\vspace*{0.25in} - \begin{lstlisting} -In []: def f(a, *, b=False): - ...: print(a, b) - -In []: f(1, 20) -TypeError: f() takes 1 positional arg... -\end{lstlisting} -\pause - \begin{lstlisting} -In []: f(1, b=20) -1 20 - \end{lstlisting} -\end{frame} - -\begin{frame} - \frametitle{Discussion} - \begin{itemize} - \item Solves the problem nicely - \item \typ{b}: can only be specified as keyword argument - - \item Cannot be called as a positional argument - \end{itemize} -\end{frame} - - -\end{document} |