Difference between revisions of "Python-3.4.3/C2/Getting-started-with-strings/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "'''Python/C2/Getting Started with Strings/English'''<div style="margin-left:0cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">'''Title of script'''<...")
 
 
(21 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''Python/C2/Getting Started with Strings/English'''<div style="margin-left:0cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">'''Title of script'''</span><span style="background-color:#ffffff;color:#000000;">: </span><span style="background-color:#ffffff;color:#000000;">'''Getting Started with Strings'''</span></div>
+
'''Python/C2/Getting Started with Strings/English''''''Title of script''': '''Getting Started with Strings'''
  
<div style="margin-left:0cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">'''Author: </span>Trupti Kini'''</div>
+
'''Author: Trupti Kini'''
  
<div style="margin-left:0cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">'''Keywords: Python, Ipython'''</span></div><div style="margin-left:0cm;margin-right:0cm;"></div>
 
  
 +
{| style="border-spacing:0;"
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <center>'''Visual Cue'''</center>
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <center>'''Narration'''</center>
  
{| style="border-spacing:0;width:17.806cm;"
+
|-
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide  
| align=center| <span style="background-color:#ffffff;color:#000000;">'''Visual Cue'''</span>
+
| align=center| <span style="background-color:#ffffff;color:#000000;">'''Narration'''</span>
+
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <span style="background-color:#ffffff;color:#000000;">Show Slide </span>
+
  
<span style="background-color:#ffffff;color:#000000;">containing title, name of the production team along with the logo of MHRD </span>
+
containing title, name of the production team along with the logo of MHRD  
|| <span style="background-color:#ffffff;color:#000000;">Hello Friends. Welcome to the tutorial on "</span><span style="background-color:#ffffff;color:#000000;">'''Getting Started with Strings'''</span><span style="background-color:#ffffff;color:#000000;">". </span>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Hello Friends. Welcome to the tutorial on "'''Getting Started with Strings'''".
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <span style="background-color:#ffffff;color:#000000;">Show Slide </span>
+
  
<span style="background-color:#ffffff;color:#000000;">Objectives </span>
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide
  
 +
Objectives
  
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| At the end of this tutorial, you will learn to,
  
|| <span style="background-color:#ffffff;color:#000000;">At the end of this tutorial, you will</span> learn<span style="background-color:#ffffff;color:#000000;"> to, </span>
+
# Define strings in different ways.
 +
# Concatenate strings.
 +
# Print a string repeatedly.
 +
# Access individual elements of the string.
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show slide
  
# <div style="margin-left:1.27cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">Define strings in different ways. </span></div>
+
System Specifications
# <div style="margin-left:1.27cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">Concatenate strings. </span></div>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| To record this tutorial, I am using
# <div style="margin-left:1.27cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">Print a string repeatedly. </span></div>
+
# <div style="margin-left:1.27cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">Access individual elements of the string. </span></div>
+
  
# <div style="margin-left:1.247cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">Learn immutability of strings. </span></div>
+
* '''Ubuntu Linux 16.04''' operating system
 +
* '''Python 3.4.3''' and
 +
* '''IPython 5.1.0'''
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide
  
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
Pre-requisites
|| <span style="background-color:#ffffff;color:#000000;">Show slide</span>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| To practise this tutorial, you should know how to
  
<span style="background-color:#ffffff;color:#000000;">System Specifications </span>
+
* run basic '''Python '''commands on the '''ipython console'''
|| <span style="background-color:#ffffff;color:#000000;">To record this tutorial, I am using </span>* <div style="margin-left:1.27cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">'''Ubuntu Linux 1</span>6<span style="background-color:#ffffff;color:#000000;">.04'''</span><span style="background-color:#ffffff;color:#000000;"> operating system</span></div>
+
* <div style="margin-left:1.27cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">'''Python 3.4.3'''</span></div>
+
* <div style="margin-left:1.27cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">'''IPython 5.1.0'''</span></div>
+
  
 +
If not, see the pre-requisite '''Python '''tutorials on this website.
  
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|-
|| <span style="background-color:#ffffff;color:#000000;">Show Slide </span>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide  
 
+
<span style="background-color:#ffffff;color:#000000;">Pre-requisites</span>
+
|| <span style="background-color:#ffffff;color:#000000;">To practise this tutorial, you should know how to </span>* <div style="margin-left:1.27cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">run basic </span><span style="background-color:#ffffff;color:#000000;">'''Python '''</span><span style="background-color:#ffffff;color:#000000;">commands on the </span><span style="background-color:#ffffff;color:#000000;">'''ipython console'''</span></div>
+
 
+
 
+
 
+
<div style="color:#000000;"></div>
+
 
+
<span style="background-color:#ffffff;color:#000000;">If not, see the pre-requisite </span><span style="background-color:#ffffff;color:#000000;">'''Python '''</span><span style="background-color:#ffffff;color:#000000;">tutorials on this website.</span>
+
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <span style="background-color:#ffffff;color:#000000;">Show Slide </span>
+
  
 
What are Strings?
 
What are Strings?
  
<span style="background-color:#ffffff;">In </span><span style="background-color:#ffffff;">'''Python,'''</span><span style="background-color:#ffffff;"> any character within a </span><span style="background-color:#ffffff;color:#333333;">'''single/ double/ triple </span><span style="background-color:#ffffff;">quotes '''</span><span style="background-color:#ffffff;">is</span><span style="background-color:#ffffff;">''' '''</span><span style="background-color:#ffffff;">a</span><span style="background-color:#ffffff;">''' string.'''</span>
+
In '''Python,''' any character within '''single/ double/ triple quotes '''is''' '''a''' string.'''
 
+
 
+
Example:
+
  
 
'This is a string'
 
'This is a string'
Line 68: Line 58:
  
 
‘’’This can be a large string’’’
 
‘’’This can be a large string’’’
|| <span style="background-color:#ffffff;color:#000000;">What are </span><span style="background-color:#ffffff;color:#000000;">'''strings'''</span><span style="background-color:#ffffff;color:#000000;">? </span>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| What are '''strings'''?  
  
<span style="background-color:#ffffff;color:#000000;">In </span><span style="background-color:#ffffff;color:#000000;">'''Python,'''</span><span style="background-color:#ffffff;color:#000000;"> any</span><span style="background-color:#ffffff;"> character</span><span style="background-color:#ffffff;color:#000000;"> within </span><span style="background-color:#ffffff;">a </span><span style="background-color:#ffffff;color:#333333;">'''single/ double/ triple </span><span style="background-color:#ffffff;color:#000000;">quotes '''</span><span style="background-color:#ffffff;color:#000000;">is</span><span style="background-color:#ffffff;color:#000000;">''' '''</span><span style="background-color:#ffffff;color:#000000;">a</span><span style="background-color:#ffffff;color:#000000;">''' string.'''</span>
+
In '''Python,''' any character within a '''single/ double/ triple quotes '''is''' '''a''' string.'''
  
<span style="background-color:#ffffff;color:#000000;">For example: </span>
+
For example:  
  
<span style="background-color:#ffffff;">Single, double, and t</span><span style="background-color:#ffffff;color:#000000;">riple </span><span style="background-color:#ffffff;color:#000000;">'''quotes'''</span><span style="background-color:#ffffff;color:#000000;"> can be</span><span style="background-color:#ffffff;"> used to denote a</span><span style="background-color:#ffffff;color:#000000;"> </span><span style="background-color:#ffffff;color:#000000;">'''string '''</span><span style="background-color:#ffffff;color:#000000;">as shown here.</span>
+
Single, double, and triple '''quotes''' can be used to denote a '''string '''as shown here.
 
+
 
+
 
+
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| Show Slide
+
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide
  
 
What are Strings?
 
What are Strings?
|| <span style="background-color:#ffffff;">'''Strings'''</span><span style="background-color:#ffffff;"> in triple </span><span style="background-color:#ffffff;">'''quotes'''</span><span style="background-color:#ffffff;"> can be written in multiple </span><span style="background-color:#ffffff;">'''lines'''</span><span style="background-color:#ffffff;">.</span>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| '''Strings''' in triple '''quotes''' can be written in multiple '''lines'''.
  
 +
We can also define empty '''strings'''.
  
<span style="background-color:#ffffff;">We can also define empty </span><span style="background-color:#ffffff;">'''strings'''</span><span style="background-color:#ffffff;">.</span>
+
'''String''' is a collection of characters which cannot be modified after it is created.
  
 
'''String''' is an '''immutable''' '''collection'''.
 
 
That is, '''string''' cannot be '''modified''' after it is created.
 
 
 
'''String''' is a collection of characters which cannot be modified after it is created.
 
 
|-
 
|-
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;" | [Terminal]
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <nowiki>[Terminal]</nowiki>
  
 
'''ipython3'''
 
'''ipython3'''
  
 +
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.014cm;padding-right:0.191cm;"| Let us first open the '''Terminal '''by pressing '''Ctrl+Alt+T '''keys simultaneously.
  
 +
Type '''ipython3''' and press '''Enter'''.
  
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.014cm;padding-right:0.191cm;" | Let us first open the '''Terminal '''by pressing '''Ctrl+Alt+T '''keys simultaneously.
+
|-
 +
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.014cm;padding-right:0.191cm;"| <nowiki>[IPython console]</nowiki>
  
 +
'''%pylab '''and press '''Enter.'''
 +
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.014cm;padding-right:0.191cm;"| Let us initialise the '''pylab''' package.
  
Now, type '''ipython3''' and press '''Enter'''.
+
Type '''%pylab '''and press''' Enter.'''
|- style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.014cm;padding-right:0.191cm;"
+
|| [IPython console]
+
  
'''%pylab '''and press '''Enter.'''
+
|-
|| Let us initialise the '''pylab''' package.
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <nowiki>[IPython Terminal]</nowiki> Type
  
 +
'''a = 'Hello, World!' '''
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Let us clear the terminal.
  
Type '''%pylab '''and press''' Enter.'''
+
We can assign a '''string''' to a '''variable '''called '''a.'''
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <span style="background-color:#ffffff;color:#000000;">[IPython Terminal]</span>
+
  
'''a<span style="background-color:#ffffff;color:#000000;"> = 'Hello, World!' '''</span>
+
Type '''a '''''is equal to inside any quotes'' '''Hello''' ''comma'' '''World''' '''exclamation mark '''and
|| <span style="background-color:#ffffff;color:#000000;">We can assign a </span><span style="background-color:#ffffff;color:#000000;">'''string'''</span><span style="background-color:#ffffff;color:#000000;"> to a </span><span style="background-color:#ffffff;color:#000000;">'''variable '''</span><span style="background-color:#ffffff;color:#000000;">called </span>'''a<span style="background-color:#ffffff;color:#000000;">.'''</span><span style="background-color:#ffffff;color:#000000;"> </span>
+
 
+
<span style="background-color:#ffffff;color:#000000;">Type </span>'''a<span style="background-color:#ffffff;color:#000000;"> '''</span>''is equal to inside any quotes'' <span style="background-color:#ffffff;color:#333333;">'''Hello'''</span><span style="background-color:#ffffff;color:#333333;"> </span><span style="background-color:#ffffff;color:#333333;">''comma''</span><span style="background-color:#ffffff;color:#333333;"> </span><span style="background-color:#ffffff;color:#333333;">'''World'''</span><span style="background-color:#ffffff;color:#333333;"> </span><span style="background-color:#ffffff;color:#333333;">'''exclamation mark'''</span>
+
  
 
Press '''Enter'''
 
Press '''Enter'''
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
 
|| <span style="background-color:#ffffff;color:#000000;">[IPython Terminal]</span>
 
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <nowiki>[IPython Terminal]</nowiki>
  
<div style="color:#000000;"></div>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Now let us learn string concatenation.
|| Now let us learn string concatenation.
+
  
L<span style="background-color:#ffffff;color:#333333;">et us assign strings to variables.</span>
+
Let us assign strings to variables.
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
 
|| '''x = 'Hello' '''
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Type '''x = 'Hello' '''
  
 
'''y = 'World''''
 
'''y = 'World''''
  
'''z = x + ', ' + y + '!''''
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Type  
 
+
'''print(z)'''
+
|| Type  
+
  
'''x '''''is equal to inside quotes''''' Hello'''
+
'''x ''is equal to''' inside quotes'' '''Hello'''
  
 
Press '''Enter'''
 
Press '''Enter'''
  
'''y '''''is equal to inside quotes''''' World'''
+
'''y ''is equal to''' inside quotes'' '''World'''
  
 
Press '''Enter'''
 
Press '''Enter'''
  
Now, let us add the two strings.
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Type '''z = x + ', ' + y + '!''''
  
 +
'''print(z)'''
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Now, let us add the two strings.
  
'''z '''''is equal to '''''x '''''plus'' ''inside quotes''''' '''''comma''''' '''''plus''''' y '''''plus''''' '''''inside quotes '''''exclamation mark.'''
+
'''z ''is equal to ''x plus''' ''inside quotes'' '''comma plus y plus''' ''inside quotes '''exclamation mark.'''''
  
 
Press '''Enter'''
 
Press '''Enter'''
  
print ''inside parentheses'' '''z'''
+
'''print''' ''inside parentheses'' '''z'''
  
 
Press '''Enter'''
 
Press '''Enter'''
  
Here '''x '''and '''y''' are '''string''' '''variables'''.
+
Here '''x '''and '''y''' are '''string variables'''.
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Highlight +
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| The '''addition''' '''operation''' performs the '''concatenation''' of two '''strings'''.
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Highlight '''Hello, World!'''
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Here we can see the output of string concatenation.
  
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|-
|| Highlight +
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Type '''clear'''
|| <span style="background-color:#ffffff;color:#000000;">The </span><span style="background-color:#ffffff;color:#000000;">'''addition'''</span><span style="background-color:#ffffff;color:#000000;"> </span><span style="background-color:#ffffff;color:#000000;">'''operation'''</span><span style="background-color:#ffffff;color:#000000;"> performs the </span><span style="background-color:#ffffff;color:#000000;">'''concatenation'''</span><span style="background-color:#ffffff;color:#000000;"> of two </span><span style="background-color:#ffffff;color:#000000;">'''strings'''</span><span style="background-color:#ffffff;color:#000000;">. </span>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Let us clear the '''terminal'''.
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <span style="color:#ff0000;">Highlight the output</span>
+
|| <span style="color:#ff0000;">Here we can see the output of string concatenation.</span>
+
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <span style="background-color:#ffffff;color:#000000;">[IPython Terminal]</span>
+
  
Press Up arrow till we get '''x'''
+
What if we multiply a string with an integer?
 
+
 
+
'''x<span style="background-color:#ffffff;color:#000000;"> * 5'''</span>
+
|| What if we<span style="background-color:#ffffff;color:#000000;"> multiply a string with an integer</span>?
+
  
 
Let us find out!
 
Let us find out!
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <nowiki>[IPython Terminal]</nowiki>
  
<span style="background-color:#ffffff;color:#000000;">Type </span>
+
Press Up arrow till we get '''x'''
  
Recall''' x''' string.
+
Type '''x * 5'''
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"|Recall''' x''' string.
  
 
Press '''Enter'''
 
Press '''Enter'''
Line 190: Line 171:
  
 
Press '''Enter'''
 
Press '''Enter'''
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
 
|| <span style="background-color:#ffffff;color:#000000;">Show Ipython Terminal </span>
 
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Ipython Terminal
  
<span style="background-color:#ffffff;color:#000000;">Highlight the output</span>
+
Highlight '''HelloHelloHelloHelloHello'''
|| <span style="background-color:#ffffff;color:#000000;">The </span><span style="background-color:#ffffff;color:#000000;">'''string'''</span><span style="background-color:#ffffff;color:#000000;"> </span><span style="background-color:#ffffff;color:#000000;">'''Hello'''</span><span style="background-color:#ffffff;color:#000000;"> is repeated 5 times after </span><span style="background-color:#ffffff;color:#000000;">'''multiplying'''</span><span style="background-color:#ffffff;color:#000000;">. </span>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| The '''string''' '''Hello''' is repeated 5 times after '''multiplying'''.
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <span style="background-color:#ffffff;color:#000000;">Show Slide</span>
+
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide
  
<span style="background-color:#ffffff;color:#000000;">Exercise 1 </span>
+
Exercise 1
|| <span style="background-color:#ffffff;color:#000000;">Pause the video. Try this exercise and then resume the video.</span>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Pause the video. Try this exercise and then resume the video.
  
 +
Obtain the '''string''' as shown without '''typing''' out all the twenty '''hyphens'''.
  
# <div style="margin-left:1.247cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">Obtain the </span><span style="background-color:#ffffff;color:#000000;">'''string'''</span><span style="background-color:#ffffff;color:#000000;"> </span><span style="background-color:#ffffff;color:#000000;">%% --------------------%%</span><span style="background-color:#ffffff;color:#000000;"> (20 </span><span style="background-color:#ffffff;color:#000000;">'''hyphens'''</span><span style="background-color:#ffffff;color:#000000;">) without </span><span style="background-color:#ffffff;color:#000000;">'''typing'''</span><span style="background-color:#ffffff;color:#000000;"> out all the twenty </span><span style="background-color:#ffffff;color:#000000;">'''hyphens'''</span><span style="background-color:#ffffff;color:#000000;">. </span></div>
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <nowiki>[IPython Terminal]</nowiki> Type,
  
 +
'''s = "%% " + "-"*20 + "%%"'''
  
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
'''print(s)'''
|| <span style="background-color:#ffffff;color:#000000;">[IPython Terminal]</span>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Switch to the terminal for solution.
  
 +
Type,
  
<span style="background-color:#ffffff;color:#000000;">'''s = "%% " + "-"*20 + "%%"'''</span>
+
'''s ''is equal to''' inside quotes'' '''two percentages ''plus''' inside quotes '''hyphen multiplied by'' twenty ''plus''' inside quotes'' ''' two percentages'''
 
+
<span style="background-color:#ffffff;color:#000000;">'''print(s)'''</span>
+
|| <span style="background-color:#ffffff;color:#000000;">Switch to terminal for solution.</span>
+
 
+
 
+
<span style="background-color:#ffffff;color:#000000;">Type </span>
+
 
+
<span style="background-color:#ffffff;color:#000000;">'''s '''</span>''is equal to inside quotes''''' two percentages '''''plus inside quotes''<span style="background-color:#ffffff;color:#000000;">''' hyphen '''</span>''multiplied by''''' twenty''''' plus''''' '''''inside quotes''''' two percentages'''
+
  
 
Press '''Enter'''
 
Press '''Enter'''
  
'''print '''''inside parentheses '''''s'''
+
'''print''' ''inside parentheses '' '''s'''
  
 
Press '''Enter'''
 
Press '''Enter'''
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
 
| style="color:#000000;" |
 
|| <span style="background-color:#ffffff;color:#000000;">Let's now look at </span><span style="background-color:#ffffff;color:#000000;">'''accessing'''</span><span style="background-color:#ffffff;color:#000000;"> individual </span><span style="background-color:#ffffff;color:#000000;">'''elements'''</span><span style="background-color:#ffffff;color:#000000;"> of </span><span style="background-color:#ffffff;color:#000000;">'''strings'''</span><span style="background-color:#ffffff;color:#000000;">. </span>
 
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"|
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Let's now look at '''accessing''' individual '''elements''' of '''strings'''.
  
<span style="background-color:#ffffff;color:#000000;">We can access individual </span>elements<span style="background-color:#ffffff;color:#000000;"> in the </span><span style="background-color:#ffffff;color:#000000;">'''string'''</span><span style="background-color:#ffffff;color:#000000;"> using the </span><span style="background-color:#ffffff;color:#000000;">'''subscripts.'''</span><span style="background-color:#ffffff;color:#000000;"> </span>
+
We can access individual '''elements''' in the '''string''' using the '''subscripts.'''  
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <div style="color:#000000;"></div>
+
  
<span style="background-color:#ffffff;color:#000000;">[IPython Terminal]</span>
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <nowiki>[IPython Terminal]</nowiki>
  
 
Press Up arrow till we get '''a'''
 
Press Up arrow till we get '''a'''
  
<span style="background-color:#ffffff;color:#000000;">'''a[0] '''</span>
+
'''<nowiki>Type a[0] </nowiki>'''
  
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Let us clear the '''terminal'''.
  
 +
Recall '''a.'''
  
|| Recall '''a.'''
+
Press '''Enter'''.
  
 
Type,
 
Type,
  
<span style="background-color:#ffffff;color:#000000;">'''a '''</span><span style="background-color:#ffffff;color:#000000;">''inside square brackets zero ''</span><span style="background-color:#ffffff;color:#000000;">gives us the first </span><span style="background-color:#ffffff;color:#000000;">'''character'''</span><span style="background-color:#ffffff;color:#000000;"> </span>of<span style="background-color:#ffffff;color:#000000;"> the </span><span style="background-color:#ffffff;color:#000000;">'''string'''</span><span style="background-color:#ffffff;color:#000000;">. </span>
+
'''a '''''inside square brackets'' '''zero''' press '''Enter''', gives us the first '''character''' of the '''string'''.  
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"|
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| The '''indexing''' starts from 0 and goes up to '''(n-1)'''.
  
<span style="background-color:#ffffff;color:#000000;">The </span><span style="background-color:#ffffff;color:#000000;">'''indexing'''</span><span style="background-color:#ffffff;color:#000000;"> starts from 0 and goes up to </span><span style="background-color:#ffffff;color:#000000;">'''(n-1)'''</span><span style="background-color:#ffffff;color:#000000;">.</span>
+
where 'n' is the total number of '''characters''' in a '''string'''.  
  
 +
We can '''access''' the '''strings''' from the end using '''negative indices.'''
  
<span style="background-color:#ffffff;color:#000000;">where 'n' is the total number of </span><span style="background-color:#ffffff;color:#000000;">'''characters'''</span><span style="background-color:#ffffff;color:#000000;"> in a </span><span style="background-color:#ffffff;color:#000000;">'''string'''</span><span style="background-color:#ffffff;color:#000000;">. </span>
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <nowiki>[IPython Terminal]</nowiki>
  
 +
'''<nowiki>Type a[-1] </nowiki>'''
  
<span style="background-color:#ffffff;color:#000000;">We can </span><span style="background-color:#ffffff;color:#000000;">'''access'''</span><span style="background-color:#ffffff;color:#000000;"> the </span><span style="background-color:#ffffff;color:#000000;">'''strings'''</span><span style="background-color:#ffffff;color:#000000;"> from the end using </span><span style="background-color:#ffffff;color:#000000;">'''negative'''</span><span style="background-color:#ffffff;color:#000000;"> </span><span style="background-color:#ffffff;color:#000000;">'''indices.'''</span>
+
'''<nowiki>Type a[-2]</nowiki>'''
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| '''a '''''inside square brackets '''''minus one'' '''''gives us the last '''element''' of the '''string''' i.e. '''exclamation mark'''
|| <span style="background-color:#ffffff;color:#000000;">[IPython Terminal]</span>
+
  
 +
'''a '''''inside square brackets '''''minus two''' gives us the second '''element''' from the end of the '''string''' i.e. '''d'''
  
<span style="background-color:#ffffff;color:#000000;">'''a[-1] '''</span>
+
|-
 
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide
<span style="background-color:#ffffff;color:#000000;">'''a[-2]'''</span>
+
|| <span style="background-color:#ffffff;color:#000000;">'''a '''</span>''inside square brackets '''''minus one'' '''''<span style="background-color:#ffffff;color:#000000;">gives us the last </span><span style="background-color:#ffffff;color:#000000;">'''element'''</span><span style="background-color:#ffffff;color:#000000;"> of the </span><span style="background-color:#ffffff;color:#000000;">'''string'''</span> i.e. '''!'''
+
 
+
 
+
<span style="background-color:#ffffff;color:#000000;">'''a '''</span>''inside square brackets '''''minus two'''<span style="background-color:#ffffff;color:#000000;"> gives us second </span><span style="background-color:#ffffff;color:#000000;">'''element'''</span><span style="background-color:#ffffff;color:#000000;"> from the end of the </span><span style="background-color:#ffffff;color:#000000;">'''string'''</span> i.e. '''d'''
+
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <div style="color:#000000;"></div>
+
 
+
<span style="background-color:#ffffff;color:#000000;">Show Slide</span>
+
  
 
Exercise 2
 
Exercise 2
Line 279: Line 254:
 
what is the output of  
 
what is the output of  
  
'''s[-5]'''
+
'''<nowiki>s[-5]</nowiki>'''
  
'''s[-10]'''
+
'''<nowiki>s[-10]</nowiki>'''
  
'''s[-15] '''
+
'''<nowiki>s[-15] </nowiki>'''
  
'''s[15]'''
+
'''<nowiki>s[15]</nowiki>'''
  
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Pause the video. Try this exercise and then resume the video.
  
<div style="color:#000000;"></div>
+
Given a string, '''s''' which is '''Hello World''', what is the output of the following
|| <span style="background-color:#ffffff;color:#000000;">Pause the video. Try this exercise and then resume the video.</span>
+
  
  
<span style="background-color:#ffffff;color:#000000;">Given a string, </span><span style="background-color:#ffffff;color:#000000;">'''s'''</span><span style="background-color:#ffffff;color:#000000;"> which is </span><span style="background-color:#ffffff;color:#000000;">'''Hello World'''</span><span style="background-color:#ffffff;color:#000000;">, what is the output of </span>
 
  
<span style="background-color:#ffffff;color:#000000;">'''s[-5]'''</span>
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <nowiki>[Ipython Terminal]</nowiki>Type
  
<span style="background-color:#ffffff;color:#000000;">'''s[-10]'''</span>
+
'''s = "Hello World”'''
  
<span style="background-color:#ffffff;color:#000000;">'''s[-15] '''</span>
+
'''<nowiki>s[-5]</nowiki>'''
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Switch to the '''terminal'''.
  
<span style="background-color:#ffffff;color:#000000;">'''s[15]'''</span>
+
Let us clear the '''terminal'''.
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <span style="background-color:#ffffff;color:#000000;">[Ipython Terminal]</span>
+
 
+
<span style="background-color:#ffffff;color:#000000;">'''s = "Hello World</span>”'''
+
 
+
<span style="background-color:#ffffff;color:#000000;">'''s[-5]'''</span>
+
|| Switch to the terminal.
+
  
 
Type
 
Type
  
'''s '''''is equal to inside quotes''''' Hello World '''press '''Enter'''
+
'''s ''is equal to''' inside quotes'' ''' Hello World '''press '''Enter'''
  
<span style="background-color:#ffffff;color:#000000;">'''s '''</span>''inside square brackets '''''minus five'''<span style="background-color:#ffffff;color:#000000;"> gives us </span>'''W '''
+
'''s '''''inside square brackets '''minus'' five''' gives '''W '''
  
Similarly we will get '''e '''for s[-10].
+
Similarly we will get '''e '''<nowiki>for s[-10].</nowiki>
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <span style="background-color:#ffffff;color:#000000;">[Ipython Terminal]</span>
+
  
<span style="background-color:#ffffff;color:#000000;">'''s[-15]'''</span><span style="background-color:#ffffff;color:#000000;"> </span>
+
|-
|| <span style="background-color:#ffffff;color:#000000;">'''s '''</span>''inside square brackets '''''minus <span style="background-color:#ffffff;color:#000000;">15'''</span><span style="background-color:#ffffff;color:#000000;"> gives us an </span><span style="background-color:#ffffff;color:#000000;">'''IndexError</span>. '''S<span style="background-color:#ffffff;color:#000000;">ince the string given to us is only 11 </span><span style="background-color:#ffffff;color:#000000;">'''characters'''</span><span style="background-color:#ffffff;color:#000000;"> long. </span>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <nowiki>[Ipython Terminal]</nowiki>
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <span style="background-color:#ffffff;color:#000000;">[Ipython Terminal]</span>
+
  
<span style="background-color:#ffffff;color:#000000;">'''s[15]'''</span><span style="background-color:#ffffff;color:#000000;"> </span>
+
'''<nowiki>Type s[-15]</nowiki>'''  
|| '''s '''''inside square brackets '''''15 '''ag<span style="background-color:#ffffff;color:#000000;">ain </span>gives<span style="background-color:#ffffff;color:#000000;"> </span><span style="background-color:#ffffff;color:#000000;">'''IndexError '''</span>for the same reason.
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| '''s '''''inside square brackets '''''minus 15''' gives us an '''IndexError. '''
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <span style="background-color:#ffffff;color:#000000;">[Ipython Terminal]</span>
+
  
Press Up arrow till we get '''x'''
 
  
'''x<span style="background-color:#ffffff;color:#000000;">[0] = '</span>B<span style="background-color:#ffffff;color:#000000;">''''</span>
+
Since the string given to us is only 11 '''characters''' long.
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <nowiki>[Ipython Terminal]</nowiki>
  
'''Highlight the error.'''
+
'''<nowiki>Type s[15]</nowiki>'''  
|| <span style="background-color:#ffffff;color:#000000;">Let us attempt to change one of the </span><span style="background-color:#ffffff;color:#000000;">'''characters'''</span><span style="background-color:#ffffff;color:#000000;"> in a </span><span style="background-color:#ffffff;color:#000000;">'''string'''</span><span style="background-color:#ffffff;color:#000000;">.</span>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| '''s '''''inside square brackets '''''15 '''again gives '''IndexError '''for the same reason.
  
Type,
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <nowiki>[Ipython Terminal]</nowiki>
  
Recall '''x'''
+
Press Up arrow till we get '''x'''
 +
Type
  
Let us manipulate '''x.'''
+
'''x<nowiki>[0] = '</nowiki>B''''
  
'''x '''''inside square brackets '''''zero '''''equal to inside quotes '''''B '''press '''Enter'''
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Let us attempt to change one of the '''characters''' in a '''string'''.
  
 +
Let us clear the '''terminal'''.
  
Why do we get an error?
+
Recall '''x'''
  
Initially the value of x[0] is ‘H’. Now we are trying to assign another value ‘B’ to x[0].
+
Press '''Enter'''
  
Recall, strings cannot be modified after it is created.
+
Let us manipulate '''x.'''
  
 +
'''x ''' ''inside square brackets '' '''zero ''equal to''' inside quotes '' '''B '''press '''Enter'''
  
We are trying to change the value of x[0] which was ‘'''H’ '''to''' B'.'''
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| '''Highlight the error'''
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Why do we get an error?
  
We are getting added anan error because, '''strings''' are '''immutable''' and so cannot be manipulated.
+
Initially the value of '''x[0]''' is '''‘H’'''.
  
 +
Now we are trying to assign another value '''‘B’''' to '''x[0]'''.
  
 +
Recall, strings cannot be modified after it is created.
  
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|-
|| Show slide
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show slide '''split()''' and''' join()''' functions
|| We can split and join the strings by using the functions :
+
  
split() and join()
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| We can split and join the strings by using the functions :
  
 +
'''split()''' and''' join()'''
  
 
+
|-
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show slide
|| Show slide
+
  
 
Syntax for''' join()'''
 
Syntax for''' join()'''
  
 
'''str.join(sequence)'''
 
'''str.join(sequence)'''
||  
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| To join a string, the syntax is
  
To join a string
+
'''str ''dot join''' inside parentheses'' '''sequence'''
  
'''str '''''dot join inside parentheses'' '''sequence'''
+
|-
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <nowiki>[Ipython Terminal]</nowiki>
|| [Ipython Terminal]
+
  
s = “-”seq = ("a", "b", "c"); print (s.join( seq ))
+
s = “-
  
 +
seq = ("a", "b", "c")
  
 +
print (s.join( seq ))
  
|| Switch to the terminal.
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Switch to the '''terminal'''.
 +
 
 +
Let us clear the '''terminal'''
  
 
Type
 
Type
  
s ''is equal to inside quotes '''''hyphen '''press '''Enter'''seq ''is equal to inside parentheses '''''a,b,c '''press '''Enter'''
+
'''s ''is equal to''' inside quotes '''hyphen '''''press '''Enter'''
  
print s ''dot '''''join''''' inside parentheses'' '''seq '''press '''Enter'''
+
'''seq ''is equal to''' inside parentheses '' '''a ''comma ''b ''comma '' c '''press '''Enter'''
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| Highlight output
+
|| We will get output as '''a-b-c'''
+
  
It has joined a, b, c with hyphen.
+
'''print s ''dot'' join''' inside parentheses '''seq '''press '''Enter'''
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
||
+
  
Show slide syntax for '''split()'''  
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Highlight '''a-b-c'''
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| We will get output as '''a '''''hyphen '''''b '''''hyphen '''''c'''
  
 +
It has joined '''a, b, c''' with '''hyphen'''.
 +
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show slide syntax for '''split()'''
  
 
str.split()
 
str.split()
|| To split a string
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| To split a string, syntax is
  
str ''dot ''split ''open and close parentheses ''
+
'''str dot split '''''open and close parentheses ''
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
 
|| [Ipython Terminal]
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| <nowiki>[Ipython Terminal]</nowiki>
  
 
str = "Line1-abcdef \nLine2-abc \nLine4-abcd";print (str.split( ))
 
str = "Line1-abcdef \nLine2-abc \nLine4-abcd";print (str.split( ))
  
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Switch to the '''terminal'''
  
 +
Type as shown press '''Enter'''
  
|| str ''is equal to ''"Line1-abcdef \nLine2-abc \nLine4-abcd" press '''Enter'''print str ''dot ''split ''open and close parentheses''''' '''press '''Enter'''
 
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
 
|| Highlight output
 
|| We get the output '''['Line1-abcdef', 'Line2-abc', 'Line4-abcd']'''
 
  
It has split the string at spaces.
+
'''print str dot split''' ''open and close parentheses'' press '''Enter'''
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
|| <span style="background-color:#ffffff;color:#000000;">Show Slide</span>
+
  
<span style="background-color:#ffffff;color:#000000;">Summary slide </span>
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Highlight '''['Line1-abcdef', 'Line2-abc', 'Line4-abcd']'''
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| We get the output like this.
  
 +
It has split the strings at '''spaces'''.
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide
  
|| <span style="background-color:#ffffff;color:#000000;">This brings us to the end of this tutorial. In this tutorial, we have learnt to,</span><span style="background-color:#ffffff;color:#000000;">''' '''</span>
+
Summary slide
  
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| This brings us to the end of this tutorial.
  
# <div style="margin-left:1.247cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">Define </span><span style="background-color:#ffffff;color:#000000;">'''strings'''</span><span style="background-color:#ffffff;color:#000000;"> in different ways. </span></div>
+
In this tutorial, we have learnt to,''' '''
  
* <div style="margin-left:1.247cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">'''Concatenate'''</span><span style="background-color:#ffffff;color:#000000;"> </span><span style="background-color:#ffffff;color:#000000;">'''strings'''</span><span style="background-color:#ffffff;color:#000000;"> by performing </span><span style="background-color:#ffffff;color:#000000;">'''addition'''</span><span style="background-color:#ffffff;color:#000000;">. </span></div>
+
* Define strings in different ways.  
* <div style="margin-left:1.247cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">Repeat a </span><span style="background-color:#ffffff;color:#000000;">'''string'''</span><span style="background-color:#ffffff;color:#000000;"> 'n' number of times by doing </span><span style="background-color:#ffffff;color:#000000;">'''multiplication'''</span><span style="background-color:#ffffff;color:#000000;">. </span></div>
+
* Concatenate strings.  
* <div style="margin-left:1.247cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">Access individual </span><span style="background-color:#ffffff;color:#000000;">'''elements'''</span><span style="background-color:#ffffff;color:#000000;"> of the string by using their </span><span style="background-color:#ffffff;color:#000000;">'''subscripts'''</span><span style="background-color:#ffffff;color:#000000;">. </span></div>
+
* Print a string repeatedly and
* <div style="margin-left:1.247cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">Use the concept of </span><span style="background-color:#ffffff;color:#000000;">'''immutability'''</span><span style="background-color:#ffffff;color:#000000;"> of </span><span style="background-color:#ffffff;color:#000000;">'''strings'''</span><span style="background-color:#ffffff;color:#000000;">. </span></div>
+
* Access individual elements of the string.  
* <div style="margin-left:1.247cm;margin-right:0cm;">Define strings in different ways. </div>
+
* <div style="margin-left:1.247cm;margin-right:0cm;">Concatenate strings. </div>
+
* <div style="margin-left:1.247cm;margin-right:0cm;">Print a string repeatedly. </div>
+
* <div style="margin-left:1.247cm;margin-right:0cm;">Access individual elements of the string. </div>
+
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide
  
 +
Evaluation
  
 +
# Write code to assign the string ’ is called the apostrophe, to a variable s
 +
# How will you change s='hello' to s='Hello'.
 +
# The variables s and t are strings and r is integer.
  
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
s=Hello
|| <span style="background-color:#ffffff;color:#000000;">Show Slide</span>
+
  
<span style="background-color:#ffffff;color:#000000;">Evaluation </span># <div style="margin-left:1.27cm;margin-right:0cm;">Write code to assign the string <span style="color:#ff0000;">' is called the apostrophe</span> , to a variable<span style="color:#ff0000;"> s</span></div>
+
t=World
# <div style="margin-left:1.27cm;margin-right:0cm;">How will you change <span style="color:#ff0000;">s='hello' to s='Hello'.</span> </div>
+
# <div style="margin-left:1.27cm;margin-right:0cm;">Change the formatting as in visual cue.The variables<span style="color:#ff0000;"> s</span> and <span style="color:#ff0000;">t </span>are <span style="color:#ff0000;">string</span> and<span style="color:#ff0000;"> r</span> is <span style="color:#ff0000;">integer</span>.</div>
+
 
+
 
+
 
+
s=”Hello”
+
 
+
t=”World”
+
  
 
r=2
 
r=2
  
 +
What is the output of s * r + t * r?
  
What is the output of <span style="color:#ff0000;">s * r + t * r? </span>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Here are some self assessment questions for you to solve
  
 +
# Write code to assign the string ’ is called the apostrophe, to variable s
 +
# How will you change '''s''' ''is equal to '''hello' to '''s''' ''is equal to capital '''h Hello'.
 +
# The variables '''s''' and '''t''' are strings and '''r''' is integer.
  
 +
They are assigned with the values as shown below,
 +
What is the output of '''s''' ''multiplied by'' '''r''''' plus'' '''t''' ''multiplied by'' '''r'''?
  
|| <span style="background-color:#ffffff;color:#000000;">Here are some self assessment questions for you to solve </span>
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide
  
 +
Solutions
  
<div style="color:#000000;"></div># <div style="margin-left:1.27cm;margin-right:0cm;">Write code to assign the string <span style="color:#ff0000;">' is called the apostrophe</span> , to variable<span style="color:#ff0000;"> s</span></div>
+
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| And the answers,
# <div style="margin-left:1.27cm;margin-right:0cm;">How will you change <span style="color:#ff0000;">s='hello' to s='Hello'.</span> </div>
+
# <div style="margin-left:1.27cm;margin-right:0cm;">The variables<span style="color:#ff0000;"> s</span> and <span style="color:#ff0000;">t </span>are <span style="color:#ff0000;">string</span> and<span style="color:#ff0000;"> r</span> is <span style="color:#ff0000;">integer</span>.</div>
+
  
 +
# The given string can be assigned in this manner
 +
# Strings cannot be manipulated after it is assigned a value
 +
# The operation '''s''' ''multiplied by'' '''r''''' plus'' '''t''' ''multiplied by'' '''r''' will print each of the two words twice as '''HelloHelloWorldWorld '''
  
 +
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide
  
They are assigned with the values as shown below:
+
Forum
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Please post your timed queries in this forum.
  
s=”Hello”
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide
  
t=”World”
+
Fossee Forum
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Please post your general queries on Python in this forum.
  
r=2
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide
  
 +
Textbook Companion
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| FOSSEE team coordinates the TBC project.
  
What is the output of <span style="color:#ff0000;">s * r + t * r? </span>
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide
  
 +
Acknowledgment
  
 +
http://spoken-tutorial.org
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India.
  
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
+
For more details, visit this website.
|| <span style="background-color:#ffffff;color:#000000;">Show Slide</span>
+
  
<span style="background-color:#ffffff;color:#000000;">Solutions </span>
+
|-
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| Show Slide
  
 +
Thank You
 +
| style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"| This is Trupti Kini from IIT Bombay signing off.
  
 +
Thank you.
  
|| <span style="background-color:#ffffff;color:#000000;">And the answers,</span><span style="background-color:#ffffff;color:#000000;">''' '''</span># <div style="margin-left:1.247cm;margin-right:0cm;"><span style="background-color:#ffffff;color:#000000;">The given string can be assigned in this manner </span></div>
 
 
 
 
<span style="background-color:#ffffff;color:#000000;">s = " ` is called the apostrophe"</span>
 
 
2.Strings cannot be manipulated after it is assigned a value.
 
 
 
3<span style="background-color:#ffffff;color:#000000;">.</span><span style="background-color:#ffffff;color:#000000;">The operation s * r + t * r will print each of the </span>
 
 
<span style="background-color:#ffffff;color:#000000;">two words twice as</span>
 
 
<span style="background-color:#ffffff;color:#000000;"> HelloHelloWorldWorld </span>
 
 
 
 
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
 
|| <span style="background-color:#ffffff;color:#000000;">Show Slide</span>
 
 
<span style="background-color:#ffffff;color:#000000;">Forum</span>
 
|| <span style="background-color:#ffffff;color:#000000;">Please post your timed queries in this forum.</span>
 
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
 
|| <span style="background-color:#ffffff;color:#000000;">Show Slide</span>
 
 
<span style="background-color:#ffffff;color:#000000;">Fossee Forum</span>
 
|| <span style="background-color:#ffffff;color:#000000;">Please post your general queries on Python in this forum.</span>
 
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
 
|| <span style="background-color:#ffffff;color:#000000;">Show Slide</span>
 
 
<span style="background-color:#ffffff;color:#000000;">Textbook Companion</span>
 
|| <span style="background-color:#ffffff;color:#000000;">FOSSEE team coordinates the TBC project.</span>
 
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
 
|| <span style="background-color:#ffffff;color:#000000;">Show Slide</span>
 
 
<span style="background-color:#ffffff;color:#000000;">Acknowledgment</span>
 
 
<span style="background-color:#ffffff;color:#000000;">http://spoken-tutorial.org</span>
 
|| <span style="background-color:#ffffff;color:#000000;">Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India.</span>
 
 
<span style="background-color:#ffffff;color:#000000;">For more details, visit this website.</span>
 
|- style="background-color:#ffffff;border:0.5pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.088cm;padding-right:0.191cm;"
 
|| <span style="background-color:#ffffff;color:#000000;">Show Slide</span>
 
 
<span style="background-color:#ffffff;color:#000000;">Thank You</span>
 
|| <span style="background-color:#ffffff;color:#000000;">This is _________ from IIT Bombay signing off.</span>
 
 
<span style="background-color:#ffffff;color:#000000;">Thank you.</span>
 
|-
 
 
|}
 
|}
 
 
<div style="margin-left:0cm;margin-right:0cm;"></div>
 

Latest revision as of 16:14, 22 January 2018

'Python/C2/Getting Started with Strings/English'Title of script: Getting Started with Strings

Author: Trupti Kini


Visual Cue
Narration
Show Slide

containing title, name of the production team along with the logo of MHRD

Hello Friends. Welcome to the tutorial on "Getting Started with Strings".
Show Slide

Objectives

At the end of this tutorial, you will learn to,
  1. Define strings in different ways.
  2. Concatenate strings.
  3. Print a string repeatedly.
  4. Access individual elements of the string.
Show slide

System Specifications

To record this tutorial, I am using
  • Ubuntu Linux 16.04 operating system
  • Python 3.4.3 and
  • IPython 5.1.0
Show Slide

Pre-requisites

To practise this tutorial, you should know how to
  • run basic Python commands on the ipython console

If not, see the pre-requisite Python tutorials on this website.

Show Slide

What are Strings?

In Python, any character within single/ double/ triple quotes is a string.

'This is a string'

“This is a string too”

‘’’This can be a large string’’’

What are strings?

In Python, any character within a single/ double/ triple quotes is a string.

For example:

Single, double, and triple quotes can be used to denote a string as shown here.

Show Slide

What are Strings?

Strings in triple quotes can be written in multiple lines.

We can also define empty strings.

String is a collection of characters which cannot be modified after it is created.

[Terminal]

ipython3

Let us first open the Terminal by pressing Ctrl+Alt+T keys simultaneously.

Type ipython3 and press Enter.

[IPython console]

%pylab and press Enter.

Let us initialise the pylab package.

Type %pylab and press Enter.

[IPython Terminal] Type

a = 'Hello, World!'

Let us clear the terminal.

We can assign a string to a variable called a.

Type a is equal to inside any quotes Hello comma World exclamation mark and

Press Enter

[IPython Terminal] Now let us learn string concatenation.

Let us assign strings to variables.

Type x = 'Hello'

y = 'World'

Type

x is equal to inside quotes Hello

Press Enter

y is equal to inside quotes World

Press Enter

Type z = x + ', ' + y + '!'

print(z)

Now, let us add the two strings.

z is equal to x plus inside quotes comma plus y plus inside quotes exclamation mark.

Press Enter

print inside parentheses z

Press Enter

Here x and y are string variables.

Highlight + The addition operation performs the concatenation of two strings.
Highlight Hello, World! Here we can see the output of string concatenation.
Type clear Let us clear the terminal.

What if we multiply a string with an integer?

Let us find out!

[IPython Terminal]

Press Up arrow till we get x

Type x * 5

Recall x string.

Press Enter

x multiplied by 5

Press Enter

Show Ipython Terminal

Highlight HelloHelloHelloHelloHello

The string Hello is repeated 5 times after multiplying.
Show Slide

Exercise 1

Pause the video. Try this exercise and then resume the video.

Obtain the string as shown without typing out all the twenty hyphens.

[IPython Terminal] Type,

s = "%% " + "-"*20 + "%%"

print(s)

Switch to the terminal for solution.

Type,

s is equal to inside quotes two percentages plus inside quotes hyphen multiplied by twenty plus inside quotes two percentages

Press Enter

print inside parentheses s

Press Enter

Let's now look at accessing individual elements of strings.

We can access individual elements in the string using the subscripts.

[IPython Terminal]

Press Up arrow till we get a

Type a[0]

Let us clear the terminal.

Recall a.

Press Enter.

Type,

a inside square brackets zero press Enter, gives us the first character of the string.

The indexing starts from 0 and goes up to (n-1).

where 'n' is the total number of characters in a string.

We can access the strings from the end using negative indices.

[IPython Terminal]

Type a[-1]

Type a[-2]

a inside square brackets minus one gives us the last element of the string i.e. exclamation mark

a inside square brackets minus two gives us the second element from the end of the string i.e. d

Show Slide

Exercise 2

s = “Hello World”

what is the output of

s[-5]

s[-10]

s[-15]

s[15]

Pause the video. Try this exercise and then resume the video.

Given a string, s which is Hello World, what is the output of the following


[Ipython Terminal]Type

s = "Hello World”

s[-5]

Switch to the terminal.

Let us clear the terminal.

Type

s is equal to inside quotes Hello World press Enter

s inside square brackets minus five gives W

Similarly we will get e for s[-10].

[Ipython Terminal]

Type s[-15]

s inside square brackets minus 15 gives us an IndexError.


Since the string given to us is only 11 characters long.

[Ipython Terminal]

Type s[15]

s inside square brackets 15 again gives IndexError for the same reason.
[Ipython Terminal]

Press Up arrow till we get x Type

x[0] = 'B'

Let us attempt to change one of the characters in a string.

Let us clear the terminal.

Recall x

Press Enter

Let us manipulate x.

x inside square brackets zero equal to inside quotes B press Enter

Highlight the error Why do we get an error?

Initially the value of x[0] is ‘H’.

Now we are trying to assign another value ‘B’ to x[0].

Recall, strings cannot be modified after it is created.

Show slide split() and join() functions We can split and join the strings by using the functions :

split() and join()

Show slide

Syntax for join()

str.join(sequence)

To join a string, the syntax is

str dot join inside parentheses sequence

[Ipython Terminal]

s = “-”

seq = ("a", "b", "c")

print (s.join( seq ))

Switch to the terminal.

Let us clear the terminal

Type

s is equal to inside quotes hyphen press Enter

seq is equal to inside parentheses a comma b comma c press Enter

print s dot join inside parentheses seq press Enter

Highlight a-b-c We will get output as a hyphen b hyphen c

It has joined a, b, c with hyphen.

Show slide syntax for split()

str.split()

To split a string, syntax is

str dot split open and close parentheses

[Ipython Terminal]

str = "Line1-abcdef \nLine2-abc \nLine4-abcd";print (str.split( ))

Switch to the terminal

Type as shown press Enter


print str dot split open and close parentheses press Enter

Highlight ['Line1-abcdef', 'Line2-abc', 'Line4-abcd'] We get the output like this.

It has split the strings at spaces.

Show Slide

Summary slide

This brings us to the end of this tutorial.

In this tutorial, we have learnt to,

  • Define strings in different ways.
  • Concatenate strings.
  • Print a string repeatedly and
  • Access individual elements of the string.
Show Slide

Evaluation

  1. Write code to assign the string ’ is called the apostrophe, to a variable s
  2. How will you change s='hello' to s='Hello'.
  3. The variables s and t are strings and r is integer.

s=Hello

t=World

r=2

What is the output of s * r + t * r?

Here are some self assessment questions for you to solve
  1. Write code to assign the string ’ is called the apostrophe, to variable s
  2. How will you change s is equal to hello' to s is equal to capital h Hello'.
  3. The variables s and t are strings and r is integer.

They are assigned with the values as shown below, What is the output of s multiplied by r plus t multiplied by r?

Show Slide

Solutions

And the answers,
  1. The given string can be assigned in this manner
  2. Strings cannot be manipulated after it is assigned a value
  3. The operation s multiplied by r plus t multiplied by r will print each of the two words twice as HelloHelloWorldWorld
Show Slide

Forum

Please post your timed queries in this forum.
Show Slide

Fossee Forum

Please post your general queries on Python in this forum.
Show Slide

Textbook Companion

FOSSEE team coordinates the TBC project.
Show Slide

Acknowledgment

http://spoken-tutorial.org

Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India.

For more details, visit this website.

Show Slide

Thank You

This is Trupti Kini from IIT Bombay signing off.

Thank you.

Contributors and Content Editors

Nancyvarkey, Nirmala Venkat, Trupti