diff options
author | Prabhu Ramachandran | 2017-01-30 22:18:21 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2017-01-30 22:18:21 +0530 |
commit | 326867f1109539b087874c4d227ec7c408476b3a (patch) | |
tree | a5a781259ce3fa09860b67969f692934c666a6b5 /basic_python | |
parent | 75fcf9b318fada12be10f9eb567aafae750719ff (diff) | |
download | python-workshops-326867f1109539b087874c4d227ec7c408476b3a.tar.gz python-workshops-326867f1109539b087874c4d227ec7c408476b3a.tar.bz2 python-workshops-326867f1109539b087874c4d227ec7c408476b3a.zip |
Minor fixes to slides.
Diffstat (limited to 'basic_python')
-rw-r--r-- | basic_python/basics.tex | 15 | ||||
-rw-r--r-- | basic_python/control_flow.tex | 19 |
2 files changed, 21 insertions, 13 deletions
diff --git a/basic_python/basics.tex b/basic_python/basics.tex index 3016747..9cca510 100644 --- a/basic_python/basics.tex +++ b/basic_python/basics.tex @@ -546,13 +546,13 @@ In []: a = input() 5 In []: a -Out[]: '5' +Out[]: '5' # Python 3.x! In []: a = input('Enter a value: ') Enter a value: 5 \end{lstlisting} \item Prompt string is optional. - \item All keystrokes are strings! + \item \typ{input} produces strings (Python 3.x) \item \typ{int()} converts string to int. \end{itemize} \end{frame} @@ -580,7 +580,8 @@ In []: from __future__ import print_function \begin{itemize} \item Put the following code snippet in a file \typ{hello1.py} \end{itemize} - \begin{lstlisting} +\begin{lstlisting} +from __future__ import print_function print("Hello", "World") print("Goodbye", "World") \end{lstlisting} @@ -596,6 +597,7 @@ Goodbye World \frametitle{Simple IO: Console output \ldots} Put the following code snippet in a file \typ{hello2.py} \begin{lstlisting} +from __future__ import print_function print("Hello", end=' ') print("World") \end{lstlisting} @@ -618,9 +620,10 @@ Hello World \begin{frame}[fragile] \frametitle{What did we learn?} \begin{itemize} - \item Data types: int, float, complex, boolean, string - \item Operators: +, -, *, /, \%, **, +=, -=, *=, /=, >, <, <=, >=, ==, !=, a < b < c - \item Simple IO: \kwrd{input} and \kwrd{print} + \item Data types: int, float, complex, boolean, string + \item Use \typ{type} builtin function to find the type + \item Operators: +, -, *, /, \%, **, +=, -=, *=, /=, >, <, <=, >=, ==, !=, a < b < c + \item Simple IO: \kwrd{input} and \kwrd{print} \end{itemize} \end{frame} diff --git a/basic_python/control_flow.tex b/basic_python/control_flow.tex index a299563..373b1a6 100644 --- a/basic_python/control_flow.tex +++ b/basic_python/control_flow.tex @@ -82,14 +82,19 @@ else: \item \texttt{if-else} construct or the ternary operator \end{itemize} \begin{lstlisting} - In []: if score_str != 'AA': - .....: score = int(score_str) - .....: else: - .....: score = 0 +In []: if score_str != 'AA': +.....: score = int(score_str) +.....: else: +.....: score = 0 \end{lstlisting} +\end{frame} +\begin{frame}[fragile] + \frametitle{Ternary operator} + With the ternary operator you can do this: + \small \begin{lstlisting} - In []: ss = score_str - In []: score = int(ss) if ss != 'AA' else 0 +In []: ss = score_str +In []: score = int(ss) if ss != 'AA' else 0 \end{lstlisting} \end{frame} @@ -136,8 +141,8 @@ else: \pause \item Shift \typ{a, b} to next values \begin{itemize} - \item \typ{b = next} \item \typ{a = b} + \item \typ{b = next} \end{itemize} \pause \item Repeat steps 2, 3 when \typ{b < 30} |