diff options
author | Jovina | 2011-05-25 16:29:48 +0530 |
---|---|---|
committer | Jovina | 2011-05-25 16:29:48 +0530 |
commit | 58cdb783e3e48d859cbc776373da257bf7b22cbe (patch) | |
tree | 2add894bf98e308e2080221e5dec8b2bb82f16e9 /getting_started_with_strings | |
parent | 37051a2dc7b8c0cd47f2e91391612887c0f1adb9 (diff) | |
download | st-scripts-58cdb783e3e48d859cbc776373da257bf7b22cbe.tar.gz st-scripts-58cdb783e3e48d859cbc776373da257bf7b22cbe.tar.bz2 st-scripts-58cdb783e3e48d859cbc776373da257bf7b22cbe.zip |
Modified the scripts and slides in module 2.
Diffstat (limited to 'getting_started_with_strings')
-rw-r--r-- | getting_started_with_strings/script.rst | 34 | ||||
-rw-r--r-- | getting_started_with_strings/slides.org | 8 | ||||
-rw-r--r-- | getting_started_with_strings/slides.tex | 12 |
3 files changed, 32 insertions, 22 deletions
diff --git a/getting_started_with_strings/script.rst b/getting_started_with_strings/script.rst index 6d31bee..4dd1930 100644 --- a/getting_started_with_strings/script.rst +++ b/getting_started_with_strings/script.rst @@ -97,8 +97,8 @@ By having multiple control characters, we avoid the need for escaping characters -- in this case the apostrophe. Let us now move on to the triple quoted strings. Let us define multi-line -strings without using any escaping. Everything within the triple quotes is a -single string no matter how many lines it extends +strings without using any escaping. Everything within the triple quotes +is a single string no matter how many lines it extends .. L6 :: @@ -119,10 +119,10 @@ We can assign this string to any variable .. R8 Now 'a' is a string variable. String is a collection of characters. In -addition string is an immutable collection which means that the string cannot -be modified after it is created.So all the operations that are applicable to any -other immutable collection in Python, works on strings as well. -Hence we can add two strings +addition string is an immutable collection which means that the string +cannot be modified after it is created.So all the operations that are +applicable to any other immutable collection in Python, works on strings +as well.Hence we can add two strings .. L8 :: @@ -159,7 +159,7 @@ It gives another string in which the original string 'Hello' is repeated .. L12 -{{{ Show slide with Question 1 }}} +{{{ Show slide with exercise 1 }}} .. R12 @@ -190,9 +190,9 @@ using the subscripts .. R14 -a[0] gives us the first character in the string. The indexing starts from 0 -for the first character and goes up to (n-1) for the last character,where 'n' is -the total number of characters in a string. +a[0] gives us the first character in the string. The indexing starts from +0 for the first character and goes up to (n-1) for the last character, +where 'n' is the total number of characters in a string. We can access the strings from the end using negative indices .. L15 @@ -208,13 +208,14 @@ a[-2] gives us second element from the end of the string. .. L16 -{{{ Show slide with Question 2 }}} +{{{ Show slide with exercise 2 }}} .. R16 Pause the video here, try out the following exercise and resume the video. -Given a string, ``s = "Hello World"``, what is the output of:: +Given a string, ``s = "Hello World"``, what is the output of +:: s[-5] s[-10] @@ -247,8 +248,8 @@ s[-10] gives us 'e' and .. R19 -s[-15] gives us an ``IndexError``, as should be expected, since the string -given to us is only 11 characters long. +s[-15] gives us an ``IndexError``, as should be expected, since the +string given to us is only 11 characters long. .. R20 @@ -278,7 +279,8 @@ into a single string based on the specified separator. .. R22 -Let's revise quickly what we have learnt today.In this tutorial we have learnt to, +Let's revise quickly what we have learnt today.In this tutorial we have +learnt to, 1. Define strings in differnt ways. #. Concatenate strings by performing addition. @@ -330,6 +332,6 @@ And the answers, .. R25 -Hope you have enjoyed and found it useful. +Hope you have enjoyed this tutorial and found it useful. Thank you! diff --git a/getting_started_with_strings/slides.org b/getting_started_with_strings/slides.org index cd95474..e94a9b1 100644 --- a/getting_started_with_strings/slides.org +++ b/getting_started_with_strings/slides.org @@ -53,10 +53,10 @@ - Print a string repeatedly. - Access individual elements of the string. - Learn immutability of strings. -* Question 1 +* Exercise 1 Obtain the string ~%% -------------------- %%~ (20 hyphens) without typing out all the twenty hyphens. -* Question 2 +* Exercise 2 Given a string, ~s~ which is ~Hello World~ , what is the output of:: #+begin_src python s[-5] @@ -74,9 +74,11 @@ * Evaluation 1. Write code to assign s, the string ``' is called the apostrophe`` + 2. Given strings s and t, ``s = "Hello"`` and ``t = "World"`` and an integer r, ``r = 2``. What is the output of s * r + s * t? + 3. How will you change s='hello' to s='Hello'. - s[ 0 ]= H @@ -85,8 +87,10 @@ * Solutions 1. s = "` is called the apostrophe" + 2. HelloHelloWorldWorld + 3. Strings are immutable,hence cannot be manipulated. * diff --git a/getting_started_with_strings/slides.tex b/getting_started_with_strings/slides.tex index e38ca13..7a899d9 100644 --- a/getting_started_with_strings/slides.tex +++ b/getting_started_with_strings/slides.tex @@ -1,4 +1,4 @@ -% Created 2011-05-16 Mon 12:57 +% Created 2011-05-24 Tue 11:31 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -72,14 +72,14 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \end{itemize} \end{frame} \begin{frame} -\frametitle{Question 1} +\frametitle{Exercise 1} \label{sec-3} Obtain the string \verb~%% -------------------- %%~ (20 hyphens) without typing out all the twenty hyphens. \end{frame} \begin{frame}[fragile] -\frametitle{Question 2} +\frametitle{Exercise 2} \label{sec-4} Given a string, \verb~s~ which is \verb~Hello World~ , what is the output of:: @@ -101,7 +101,7 @@ s[-15] \item To concatenate strings by performing addition. \item To repeat a string `n' number of times by doing multiplication. \item To access individual elements of the string by using their subscripts. -\item About the immutability of strings. +\item Use the concept of immutability of strings. \end{itemize} \end{frame} \begin{frame} @@ -111,8 +111,10 @@ s[-15] \begin{enumerate} \item Write code to assign s, the string ``' is called the apostrophe`` +\vspace{8pt} \item Given strings s and t, ``s = ``Hello''`` and ``t = ``World''`` and an integer r, ``r = 2``. What is the output of s * r + s * t? +\vspace{8pt} \item How will you change s='hello' to s='Hello'. \begin{itemize} \item s[ 0 ]= H @@ -128,7 +130,9 @@ s[-15] \begin{enumerate} \item s = ``` is called the apostrophe'' +\vspace{8pt} \item HelloHelloWorldWorld +\vspace{8pt} \item Strings are immutable,hence cannot be manipulated. \end{enumerate} \end{frame} |