Difference between revisions of "Python/C3/Getting-started-with-strings/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '{| border=1 !Timing !Narration |- | 0:01 | Hello friends and Welcome to the tutorial on "Getting started with strings". |- | 0:06 | At the end of this tutorial, you will be able…')
 
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{| border=1
 
{| border=1
!Timing
+
|'''Time'''
!Narration
+
|'''Narration'''
 +
 
 
|-
 
|-
| 0:01
+
| 00:01
 
| Hello friends and Welcome to the tutorial on "Getting started with strings".
 
| Hello friends and Welcome to the tutorial on "Getting started with strings".
  
 
|-
 
|-
| 0:06
+
| 00:06
 
| At the end of this tutorial, you will be able to,
 
| At the end of this tutorial, you will be able to,
 
+
Define strings in different ways.
# Define strings in different ways.
+
Concatenate strings.
# Concatenate strings.
+
Print a string repeatedly.
# Print a string repeatedly.
+
Access individual elements of the string.
# Access individual elements of the string.
+
Learn immutability of strings.
# Learn immutability of strings.
+
 
+
  
 
|-
 
|-
| 0:25
+
| 00:25
 
| Open the terminal and invoke the ipython interpreter by typing ipython, so type ipython and hit enter
 
| Open the terminal and invoke the ipython interpreter by typing ipython, so type ipython and hit enter
  
 
|-
 
|-
| 0:35
+
| 00:35
 
| So, what are strings?
 
| So, what are strings?
  
 
|-
 
|-
| 0:38
+
| 00:38
 
| In Python anything within either single quotes or double quotes or triple single quotes or triple double quotes are strings.
 
| In Python anything within either single quotes or double quotes or triple single quotes or triple double quotes are strings.
  
 
|-
 
|-
|0:51
+
|00:51
|So you can type within single quotes This is a string, then in double quotes This is a string too.
+
|So if you can type within single quotes This is a string, then in double quotes This is a string too.
  
 
|-
 
|-
|1:06
+
|01:06
 
|Then in triple double quotes This is also a string
 
|Then in triple double quotes This is also a string
  
 
|-
 
|-
| 1:26
+
| 01:26
 
| Note that it really doesn't matter how many characters are present in the string.  
 
| Note that it really doesn't matter how many characters are present in the string.  
  
 
|-
 
|-
|1:32
+
|01:32
 
|So we can even put a null string or an empty string.
 
|So we can even put a null string or an empty string.
  
 
|-
 
|-
|1:40
+
|01:40
 
|Having more than one control character to define strings is handy when one of the control characters itself is part of the string.  
 
|Having more than one control character to define strings is handy when one of the control characters itself is part of the string.  
  
 
|-
 
|-
|1:50
+
|01:50
 
|For example you can type in double quotes Python's string manipulation functions are very useful
 
|For example you can type in double quotes Python's string manipulation functions are very useful
  
 
|-
 
|-
| 2:16
+
| 02:16
 
| By having multiple control characters, we avoid the need for escaping characters hyphen hyphen in this case the apostrophe.
 
| By having multiple control characters, we avoid the need for escaping characters hyphen hyphen in this case the apostrophe.
  
 
|-
 
|-
|2:28
+
|02:28
 
|Let us now move on to the triple quoted strings.  
 
|Let us now move on to the triple quoted strings.  
  
 
|-
 
|-
|2:32
+
|02:32
 
|Let us define multi-line strings without using any escaping.
 
|Let us define multi-line strings without using any escaping.
  
 
|-
 
|-
|2:36
+
|02:36
 
| Everything within the triple quotes is a single string no matter how many lines it extends
 
| Everything within the triple quotes is a single string no matter how many lines it extends
  
 
|-
 
|-
|2:44
+
|02:44
 
|So we can type in the terminal, within triple double quotes Having more than one control character to define strings come as very handy when one of the control characters itself is part of the string.
 
|So we can type in the terminal, within triple double quotes Having more than one control character to define strings come as very handy when one of the control characters itself is part of the string.
  
 
|-
 
|-
|2:59
+
|02:59
 
|So, we can assign this string to any variable
 
|So, we can assign this string to any variable
  
 
|-
 
|-
|3:04
+
|03:04
 
|So lets type a = within single quotes Hello comma  World exclamation and hit enter
 
|So lets type a = within single quotes Hello comma  World exclamation and hit enter
  
 
|-
 
|-
| 3:17
+
| 03:17
 
| Now 'a' is a string variable.
 
| Now 'a' is a string variable.
  
 
|-
 
|-
| 3:21
+
| 03:21
 
| String is a collection of characters.
 
| String is a collection of characters.
  
 
|-
 
|-
|3:23
+
|03:23
 
| In addition string is an immutable collection which means that the string cannot be modified after it is created.
 
| In addition string is an immutable collection which means that the string cannot be modified after it is created.
  
 
|-
 
|-
|3:30
+
|03:30
 
| So all the operations that are applicable to any other immutable collection in Python, works on strings as well.
 
| So all the operations that are applicable to any other immutable collection in Python, works on strings as well.
  
 
|-
 
|-
|3:38
+
|03:38
 
| Hence we can add two strings
 
| Hence we can add two strings
  
 
|-
 
|-
|3:41
+
|03:41
 
|So lets type a = within single quotes Hello and hit enter, b = within single quotes World
 
|So lets type a = within single quotes Hello and hit enter, b = within single quotes World
  
 
|-
 
|-
|3:58
+
|03:58
 
|c = a plus in single quotes comma plus b plus in single quotes exclamation and hit enter then
 
|c = a plus in single quotes comma plus b plus in single quotes exclamation and hit enter then
 
print c
 
print c
  
 
|-
 
|-
|4:25
+
|04:25
 
|So you will get an output hello comma world
 
|So you will get an output hello comma world
  
 
|-
 
|-
| 4:33
+
| 04:33
| We can add string variables as well as the strings themselves all in the same statement.
+
| We can add string variables as well as the strings themselves in all the same statement.
  
 
|-
 
|-
|4:38
+
|04:38
 
| The same addition operation performs the concatenation of two strings.
 
| The same addition operation performs the concatenation of two strings.
  
 
|-
 
|-
4:44
+
04:44
 
| Similarly we can multiply a string with an integer
 
| Similarly we can multiply a string with an integer
  
 
|-
 
|-
|4:48
+
|04:48
 
|So lets type a =  in single quotes Hello
 
|So lets type a =  in single quotes Hello
  
 
|-
 
|-
|4:58
+
|04:58
 
|Type a into  5
 
|Type a into  5
  
 
|-
 
|-
|5:03
+
|05:03
 
|So we will get output as hello into 5
 
|So we will get output as hello into 5
  
 
|-
 
|-
| 5:09
+
| 05:09
 
| It gives another string in which the original string 'Hello' is repeated 5 times.
 
| It gives another string in which the original string 'Hello' is repeated 5 times.
  
 
|-
 
|-
| 5:16
+
| 05:16
 
| Now, pause the video here, try out the following exercise and resume the video.
 
| Now, pause the video here, try out the following exercise and resume the video.
  
 
|-
 
|-
|5:22
+
|05:22
|Obtain the string <tt>percentage percentage 20 hyphens percentage percentage</tt> without typing out all the twenty hyphens.
+
|Obtain the string percentage percentage 20 hyphens percentage percentage  without typing out all the twenty hyphens.
  
 
|-
 
|-
| 5:32
+
| 05:32
 
| Let's now look at accessing individual elements of strings.  
 
| Let's now look at accessing individual elements of strings.  
  
 
|-
 
|-
|5:37
+
|05:37
 
|Since, strings are collections, we can access individual items in the string using the subscripts
 
|Since, strings are collections, we can access individual items in the string using the subscripts
  
 
|-
 
|-
|5:44
+
|05:44
 
|So type s = within double quotes percentage percentage  plus within double quotes hyphen multiply by 20 plus within double quotes percentage percentage and hit enter
 
|So type s = within double quotes percentage percentage  plus within double quotes hyphen multiply by 20 plus within double quotes percentage percentage and hit enter
  
 
|-
 
|-
|6:11
+
|06:11
 
|Now to get an output print s
 
|Now to get an output print s
  
 
|-
 
|-
| 6:20  
+
| 06:20  
| <nowiki>a in square bracket zero gives us the first character in the string.  
+
| a in square bracket zero gives us the first character in the string.  
  
 
|-
 
|-
|6:26
+
|06:26
 
|The indexing starts from 0 for the first character and goes up to (n minus 1) for the last character, where 'n' is the total number of characters in a string.
 
|The indexing starts from 0 for the first character and goes up to (n minus 1) for the last character, where 'n' is the total number of characters in a string.
  
 
|-
 
|-
|6:39
+
|06:39
| We can access the strings from the end using negative indices</nowiki>
+
| We can access the strings from the end using negative indices
  
 
|-
 
|-
|6:44
+
|06:44
 
|So type a in square bracket zero and hit enter
 
|So type a in square bracket zero and hit enter
  
 
|-
 
|-
6:50
+
06:50
| <nowiki>a in square bracket minus 1 gives us the last element of the string and a[-2] gives us second element from the end of the string.</nowiki>So type a in square bracket minus 1 and hit enter, then a in square bracket minus 2 and hit enter
+
| a in square bracket minus 1 gives us the last element of the string and a[-2] gives us second element from the end of the string.</nowiki>So type a in square bracket minus 1 and hit enter, then a in square bracket minus 2 and hit enter
  
 
|-
 
|-
| 7:10
+
| 07:10
 
| Pause the video here, try out the following exercise and resume the video.
 
| Pause the video here, try out the following exercise and resume the video.
  
 
|-
 
|-
|7:14
+
|07:14
|Given a string, <tt>s = within double quotes Hello World</tt>, what is the output of
+
|Given a string, s = within double quotes Hello World what is the output of
  
 
|-
 
|-
|7:22
+
|07:22
|<nowiki>s[ minus 5]</nowiki>
+
|s[ minus 5]
 
+
  
 
|-
 
|-
|7:25
+
|07:25
|<nowiki>s[ minus 10]</nowiki>
+
|s[ minus 10]
  
 
|-
 
|-
|7:27
+
|07:27
|<nowiki>s[minus 15]</nowiki>
+
|s[minus 15]
  
 
|-
 
|-
| 7:34
+
| 07:34
| Now, <nowiki>s of [-5] gives us 'W'</nowiki>.So in terminal type s of [-5] and hit enter.
+
| Now, s of [-5] gives us 'W'.So in terminal type s of [-5] and hit enter.
  
 
|-
 
|-
7:45
+
07:45
| <nowiki>s of [-10] gives us 'e' and</nowiki>
+
|s of [-10] gives us 'e' and
  
 
|-
 
|-
|7:51
+
|07:51
|So we got an error of hyphen,so lets update the value of s with hello world. So type s = Hello World
+
|So we got an error as hyphen,so lets update the value of s with hello world. So type s = Hello World
  
 
|-
 
|-
|8:09
+
|08:09
 
|Now s of -5 is W. So we got the output as W
 
|Now s of -5 is W. So we got the output as W
  
 
|-
 
|-
|8:18
+
|08:18
 
|So next type s of -10, it gives us e  
 
|So next type s of -10, it gives us e  
  
 
|-
 
|-
| 8:26
+
| 08:26
| <nowiki>And s of [-15] gives us an </nowiki><tt>IndexError</tt>, as should be expected, since the string given to us is only 11 characters long.
+
|And s of [-15] gives us an IndexError,as should be expected, since the string given to us is only 11 characters long.
  
 
|-
 
|-
| 8:37
+
| 08:37
 
| Let us attempt to change one of the characters in a string
 
| Let us attempt to change one of the characters in a string
  
 
|-
 
|-
|8:42
+
|08:42
 
|So type a = 'hello' and a of [0] = 'H'
 
|So type a = 'hello' and a of [0] = 'H'
  
 
|-
 
|-
| 8:58
+
| 08:58
 
| As said earlier, strings are immutable.
 
| As said earlier, strings are immutable.
  
 
|-
 
|-
|9:01
+
|09:01
 
| We cannot manipulate a string.
 
| We cannot manipulate a string.
  
 
|-
 
|-
|9:03
+
|09:03
 
| Although there are some methods which let us manipulate strings, we will look at them in the advanced session on strings.
 
| Although there are some methods which let us manipulate strings, we will look at them in the advanced session on strings.
  
 
|-
 
|-
|9:10
+
|09:10
 
| In addition to the methods that let us manipulate the strings we have methods like split which lets us break the string on the specified separator, the join method which lets us combine the list of strings into a single string based on the specified separator.
 
| In addition to the methods that let us manipulate the strings we have methods like split which lets us break the string on the specified separator, the join method which lets us combine the list of strings into a single string based on the specified separator.
  
 
|-
 
|-
| 9:30
+
| 09:30
 
| Let's revise quickly what we have learnt today.  
 
| Let's revise quickly what we have learnt today.  
  
 
|-
 
|-
|9:33
+
|09:33
 
|In this tutorial we have learnt to,
 
|In this tutorial we have learnt to,
  
 
|-
 
|-
|9:36
+
|09:36
| 1. Define strings in different ways.
+
|Define strings in different ways.
  
 
|-
 
|-
|9:39
+
|09:39
| 2. Concatenate strings by performing addition.
+
|Concatenate strings by performing addition.
  
 
|-
 
|-
|9:42
+
|09:42
| 3.Repeat a string 'n' number of times by doing multiplication.
+
|Repeat a string 'n' number of times by doing multiplication.
  
 
|-
 
|-
|9:47
+
|09:47
| 4. Access individual elements of the string by using their subscripts.
+
|Access individual elements of the string by using their subscripts.
  
 
|-
 
|-
|9:53
+
|09:53
| 5. And finally use of the concept of immutability of strings.
+
| And finally use of the concept of immutability of strings.
 
+
 
+
  
 
|-
 
|-
| 9:58
+
| 09:58
 
| Here are some self assessment questions for you to solve
 
| Here are some self assessment questions for you to solve
  
 
|-
 
|-
 
|10:02
 
|10:02
| 1.Write code to assign s, the string <tt>' is called the apostrophe</tt>
+
| Write code to assign s, the string ' is called the apostrophe
  
 
|-
 
|-
 
|10:11
 
|10:11
| 2. Given strings s and t, <tt>s = "Hello"</tt> and <tt>t = "World"</tt> and an integer r, <tt>r = 2</tt>.
+
|Given strings s and t,s = "Hello" and t = "World" and an integer r, r = 2
  
 
|-
 
|-
Line 303: Line 299:
 
|-
 
|-
 
|10:27
 
|10:27
| 3.How will you change s='hello' to s='Hello'.with h in capital
+
|How will you change s='hello' to s='Hello'with h in capital
  
 
|-
 
|-
 
|10:37
 
|10:37
| So, <nowiki>s of [0]= H</nowiki>
+
| So, s of [0]= H
  
 
|-
 
|-
 
|10:40
 
|10:40
| <nowiki>s of [0]=in single quotes h</nowiki>
+
| s of [0]=in single quotes h
  
 
|-
 
|-
 
|10:44
 
|10:44
 
| Third option is strings are immutable,hence cannot be manipulated
 
| Third option is strings are immutable,hence cannot be manipulated
 
 
  
 
|-
 
|-
Line 325: Line 319:
 
|-
 
|-
 
|10:52
 
|10:52
|1. The given string can be assigned in this manner
+
|The given string can be assigned in this manner
  
 
|-
 
|-
Line 333: Line 327:
 
|-
 
|-
 
|11:06
 
|11:06
|2. The operation <tt> s into r plus  s into t</tt> will print each of the two words twice<br/> HelloHelloWorldWorld
+
| The operation s into r plus  s into t will print each of the two words twice Hello Hello World World
  
 
|-
 
|-

Latest revision as of 17:36, 20 February 2017

Time Narration
00:01 Hello friends and Welcome to the tutorial on "Getting started with strings".
00:06 At the end of this tutorial, you will be able to,

Define strings in different ways. Concatenate strings. Print a string repeatedly. Access individual elements of the string. Learn immutability of strings.

00:25 Open the terminal and invoke the ipython interpreter by typing ipython, so type ipython and hit enter
00:35 So, what are strings?
00:38 In Python anything within either single quotes or double quotes or triple single quotes or triple double quotes are strings.
00:51 So if you can type within single quotes This is a string, then in double quotes This is a string too.
01:06 Then in triple double quotes This is also a string
01:26 Note that it really doesn't matter how many characters are present in the string.
01:32 So we can even put a null string or an empty string.
01:40 Having more than one control character to define strings is handy when one of the control characters itself is part of the string.
01:50 For example you can type in double quotes Python's string manipulation functions are very useful
02:16 By having multiple control characters, we avoid the need for escaping characters hyphen hyphen in this case the apostrophe.
02:28 Let us now move on to the triple quoted strings.
02:32 Let us define multi-line strings without using any escaping.
02:36 Everything within the triple quotes is a single string no matter how many lines it extends
02:44 So we can type in the terminal, within triple double quotes Having more than one control character to define strings come as very handy when one of the control characters itself is part of the string.
02:59 So, we can assign this string to any variable
03:04 So lets type a = within single quotes Hello comma World exclamation and hit enter
03:17 Now 'a' is a string variable.
03:21 String is a collection of characters.
03:23 In addition string is an immutable collection which means that the string cannot be modified after it is created.
03:30 So all the operations that are applicable to any other immutable collection in Python, works on strings as well.
03:38 Hence we can add two strings
03:41 So lets type a = within single quotes Hello and hit enter, b = within single quotes World
03:58 c = a plus in single quotes comma plus b plus in single quotes exclamation and hit enter then

print c

04:25 So you will get an output hello comma world
04:33 We can add string variables as well as the strings themselves in all the same statement.
04:38 The same addition operation performs the concatenation of two strings.
04:44 Similarly we can multiply a string with an integer
04:48 So lets type a = in single quotes Hello
04:58 Type a into 5
05:03 So we will get output as hello into 5
05:09 It gives another string in which the original string 'Hello' is repeated 5 times.
05:16 Now, pause the video here, try out the following exercise and resume the video.
05:22 Obtain the string percentage percentage 20 hyphens percentage percentage without typing out all the twenty hyphens.
05:32 Let's now look at accessing individual elements of strings.
05:37 Since, strings are collections, we can access individual items in the string using the subscripts
05:44 So type s = within double quotes percentage percentage plus within double quotes hyphen multiply by 20 plus within double quotes percentage percentage and hit enter
06:11 Now to get an output print s
06:20 a in square bracket zero gives us the first character in the string.
06:26 The indexing starts from 0 for the first character and goes up to (n minus 1) for the last character, where 'n' is the total number of characters in a string.
06:39 We can access the strings from the end using negative indices
06:44 So type a in square bracket zero and hit enter
06:50 a in square bracket minus 1 gives us the last element of the string and a[-2] gives us second element from the end of the string.</nowiki>So type a in square bracket minus 1 and hit enter, then a in square bracket minus 2 and hit enter
07:10 Pause the video here, try out the following exercise and resume the video.
07:14 Given a string, s = within double quotes Hello World what is the output of
07:22 s[ minus 5]
07:25 s[ minus 10]
07:27 s[minus 15]
07:34 Now, s of [-5] gives us 'W'.So in terminal type s of [-5] and hit enter.
07:45 s of [-10] gives us 'e' and
07:51 So we got an error as hyphen,so lets update the value of s with hello world. So type s = Hello World
08:09 Now s of -5 is W. So we got the output as W
08:18 So next type s of -10, it gives us e
08:26 And s of [-15] gives us an IndexError,as should be expected, since the string given to us is only 11 characters long.
08:37 Let us attempt to change one of the characters in a string
08:42 So type a = 'hello' and a of [0] = 'H'
08:58 As said earlier, strings are immutable.
09:01 We cannot manipulate a string.
09:03 Although there are some methods which let us manipulate strings, we will look at them in the advanced session on strings.
09:10 In addition to the methods that let us manipulate the strings we have methods like split which lets us break the string on the specified separator, the join method which lets us combine the list of strings into a single string based on the specified separator.
09:30 Let's revise quickly what we have learnt today.
09:33 In this tutorial we have learnt to,
09:36 Define strings in different ways.
09:39 Concatenate strings by performing addition.
09:42 Repeat a string 'n' number of times by doing multiplication.
09:47 Access individual elements of the string by using their subscripts.
09:53 And finally use of the concept of immutability of strings.
09:58 Here are some self assessment questions for you to solve
10:02 Write code to assign s, the string ' is called the apostrophe
10:11 Given strings s and t,s = "Hello" and t = "World" and an integer r, r = 2
10:21 What is the output of s multiply r plus s multiply t?
10:27 How will you change s='hello' to s='Hello'with h in capital
10:37 So, s of [0]= H
10:40 s of [0]=in single quotes h
10:44 Third option is strings are immutable,hence cannot be manipulated
10:49 Let's look at the answers,
10:52 The given string can be assigned in this manner
10:55 So type s = in double quotes` is called the apostrophe
11:06 The operation s into r plus s into t will print each of the two words twice Hello Hello World World
11:20 Strings are immutable.
11:22 Therefore they cannot be manipulated.
11:26 Hope you have enjoyed this tutorial and found it useful.
11:29 Thank you!

Contributors and Content Editors

Gaurav, Minal, PoojaMoolya, Sneha