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

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{| border=1
 
{| border=1
!Timing
+
|'''Time'''
!Narration
+
|'''Narration'''
 +
 
 
|-
 
|-
| 0:00
+
| 00:00
 
| Hello friends and welcome to the tutorial on "getting started with tuples".
 
| Hello friends and welcome to the tutorial on "getting started with tuples".
  
 
|-
 
|-
| 0:05
+
| 00:05
 
| At the end of the tutorial, you will be able to,
 
| At the end of the tutorial, you will be able to,
 
+
Understand of what tuples are.
# Understand of what tuples are.
+
Compare them with lists.
# Compare them with lists.
+
Know why they are needed and where to use them.
# Know why they are needed and where to use them.
+
  
 
|-
 
|-
| 0:15
+
| 00:15
 
| Before beginning this tutorial,we would suggest you to complete the tutorial on "Getting started with lists".
 
| Before beginning this tutorial,we would suggest you to complete the tutorial on "Getting started with lists".
  
 
|-
 
|-
| 0:21
+
| 00:21
 
| Let us start our ipython interpreter.
 
| Let us start our ipython interpreter.
  
 
|-
 
|-
|0:23
+
|00:23
 
|Type ipython and hit Enter.
 
|Type ipython and hit Enter.
  
 
|-
 
|-
|0:27
+
|00:27
 
| Let's get started by defining a tuple.  
 
| Let's get started by defining a tuple.  
  
 
|-
 
|-
|0:29
+
|00:29
 
|A tuple is defined by enclosing parentheses around a sequence of items separated by commas.  
 
|A tuple is defined by enclosing parentheses around a sequence of items separated by commas.  
  
 
|-
 
|-
|0:39
+
|00:39
 
|It is similar to defining a list except that parentheses are used instead of square brackets.
 
|It is similar to defining a list except that parentheses are used instead of square brackets.
  
 
|-
 
|-
|0:45
+
|00:45
 
|So type t is equal to within brackets 1, 2.5, "hello",-4, "world", 1.24,5.
 
|So type t is equal to within brackets 1, 2.5, "hello",-4, "world", 1.24,5.
  
 
|-
 
|-
| 1:02
+
| 01:02
 
| The items in the tuple are indexed using numbers and can be accessed by using their position.
 
| The items in the tuple are indexed using numbers and can be accessed by using their position.
  
 
|-
 
|-
|1:10
+
|01:10
| For example,
+
| For example,First you must type t
  
 
|-
 
|-
|1:11
+
|01:18
|First you must type t
+
 
+
|-
+
|1:18
+
 
|Then type  t within square brackets 3.
 
|Then type  t within square brackets 3.
  
 
|-
 
|-
| 1:24
+
| 01:24
 
| It prints -4 which is the fourth item of the tuple.
 
| It prints -4 which is the fourth item of the tuple.
  
 
|-
 
|-
| 1:29
+
| 01:29
 
| Similarly type t within square brackets 1 colon 5 colon 2 and hit Enter.
 
| Similarly type t within square brackets 1 colon 5 colon 2 and hit Enter.
  
 
|-
 
|-
|1:40
+
|01:40
 
|It prints the corresponding slice.
 
|It prints the corresponding slice.
  
 
|-
 
|-
|1:42
+
|01:42
 
|This behaviour is similar to that of lists.
 
|This behaviour is similar to that of lists.
  
 
|-
 
|-
|1:46
+
|01:46
 
| But the difference can be seen when we try to change an element in the tuple.
 
| But the difference can be seen when we try to change an element in the tuple.
  
 
|-
 
|-
|1:51
+
|01:51
 
|So type t within square brackets 2 is equal to in double quotes Hello, H is capital.
 
|So type t within square brackets 2 is equal to in double quotes Hello, H is capital.
  
 
|-
 
|-
| 2:05
+
| 02:05
 
| We can see that, it raises an error saying 'tuple object does not support item assignment'.  
 
| We can see that, it raises an error saying 'tuple object does not support item assignment'.  
  
 
|-
 
|-
|2:10
+
|02:10
 
|Tuples are immutable, and hence cannot be changed after creation.
 
|Tuples are immutable, and hence cannot be changed after creation.
  
 
|-
 
|-
|2:13
+
|02:13
 
|Then, what is the use of tuples?
 
|Then, what is the use of tuples?
  
 
|-
 
|-
|2:16
+
|02:16
 
| We shall understand that soon.
 
| We shall understand that soon.
  
 
|-
 
|-
|2:19
+
|02:19
 
| But let us look at a simple problem of swapping values.
 
| But let us look at a simple problem of swapping values.
  
 
|-
 
|-
|2:24
+
|02:24
 
|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.
  
 
|-
 
|-
|2:30
+
|02:30
 
| Given, a is equal to 5 and b is equal to 7.
 
| Given, a is equal to 5 and b is equal to 7.
  
 
|-
 
|-
| 2:33
+
| 02:33
 
| Swap the values of a and b.
 
| Swap the values of a and b.
  
 
|-
 
|-
| 2:38
+
| 02:38
 
| Switch to terminal  for solution
 
| Switch to terminal  for solution
  
 
|-
 
|-
|2:40
+
|02:40
 
|Type a is equal to 5, then b is equal to 7 , then type a and then b, you can see the values.
 
|Type a is equal to 5, then b is equal to 7 , then type a and then b, you can see the values.
  
 
|-
 
|-
| 2:50
+
| 02:50
 
| We now create a variable say, temp and swap the values using this variable.
 
| We now create a variable say, temp and swap the values using this variable.
  
 
|-
 
|-
|2:56
+
|02:56
 
|So type temp is equal to a.Then a is equal to b ;then type b is equal to temp.
 
|So type temp is equal to a.Then a is equal to b ;then type b is equal to temp.
  
 
|-
 
|-
|3:08
+
|03:08
 
|Then type a.
 
|Then type a.
  
 
|-
 
|-
|3:10
+
|03:10
 
|Then b.
 
|Then b.
  
 
|-
 
|-
3:13
+
03:13
 
| This is the traditional approach
 
| This is the traditional approach
  
 
|-
 
|-
|3:16
+
|03:16
 
| So let us do it the python way.
 
| So let us do it the python way.
  
 
|-
 
|-
|3:21
+
|03:21
 
|So type a; then b; then a comma b is equal to b comma a.
 
|So type a; then b; then a comma b is equal to b comma a.
  
 
|-
 
|-
|3:33
+
|03:33
 
|then a ; then b  to see the output.
 
|then a ; then b  to see the output.
  
 
|-
 
|-
3:38
+
03:38
 
| We see that the values are swapped.
 
| We see that the values are swapped.
  
 
|-
 
|-
|3:43
+
|03:43
 
| This idiom works for different data-types also.
 
| This idiom works for different data-types also.
  
 
|-
 
|-
|3:46
+
|03:46
 
|So lets type a is equal to 2 point 5; then b within double quotes hello where h is small letter.
 
|So lets type a is equal to 2 point 5; then b within double quotes hello where h is small letter.
  
 
|-
 
|-
|3:59
+
|03:59
 
|Then a comma b is equal to b comma a.
 
|Then a comma b is equal to b comma a.
  
 
|-
 
|-
|4:09
+
|04:09
 
|Then a; then b.
 
|Then a; then b.
  
 
|-
 
|-
| 4:13  
+
| 04:13  
 
| Moreover this type of behavior is something that feels natural and you'd expect to happen.
 
| Moreover this type of behavior is something that feels natural and you'd expect to happen.
  
 
|-
 
|-
|4:19
+
|04:19
 
|This is possible because of the immutability of tuples.  
 
|This is possible because of the immutability of tuples.  
  
 
|-
 
|-
|4:22
+
|04:22
 
|This process is called tuple packing and unpacking.
 
|This process is called tuple packing and unpacking.
  
 
|-
 
|-
|4:26
+
|04:26
 
|So type 5 comma to see what is tuple packing
 
|So type 5 comma to see what is tuple packing
 +
 
|-
 
|-
|4:37
+
|04:37
 
|What we see in the tuple is 1 element.
 
|What we see in the tuple is 1 element.
  
 
|-
 
|-
|4:41
+
|04:41
 
|So type 5 comma within double quotes hello where h is small letter comma 2.5.
 
|So type 5 comma within double quotes hello where h is small letter comma 2.5.
  
 
|-
 
|-
|4:57
+
|04:57
 
|Now, It is a tuple with 3 elements.
 
|Now, It is a tuple with 3 elements.
  
 
|-
 
|-
|5:03
+
|05:03
 
|So when we are actually typing  2 or more elements separated by comma the elements are packed into a tuple.
 
|So when we are actually typing  2 or more elements separated by comma the elements are packed into a tuple.
  
 
|-
 
|-
|5:10
+
|05:10
 
|When we type a comma b is equal to b comma a first the value of b and a are packed into a tuple from the right side then unpack into the variables a and b.
 
|When we type a comma b is equal to b comma a first the value of b and a are packed into a tuple from the right side then unpack into the variables a and b.
  
 
|-
 
|-
|5:21
+
|05:21
 
| Immutability of tuples ensure that values are not changed during the packing and unpacking.
 
| Immutability of tuples ensure that values are not changed during the packing and unpacking.
  
 
|-
 
|-
| 5:29
+
| 05:29
 
| So This brings us to the end of this tutorial.  
 
| So This brings us to the end of this tutorial.  
  
 
|-
 
|-
|5:33
+
|05:33
 
|In this tutorial, we have learn't to,
 
|In this tutorial, we have learn't to,
  
 
|-
 
|-
|5:35
+
|05:35
|1. Define tuples.
+
|Define tuples.Understand the similarities of tuples with lists, like indexing and iterability.
  
 
|-
 
|-
|5:36
+
|05:44
|2. Understand the similarities of tuples with lists, like indexing and iterability.
+
| Know about the immutability of tuples.
  
 
|-
 
|-
|5:44
+
|05:48
|3. Know about the immutability of tuples.
+
|Swap values, the python way.
  
 
|-
 
|-
|5:48
+
|05:52
|4. Swap values, the python way.
+
|Understand the concept of packing and unpacking tuples.
  
 
|-
 
|-
|5:52
+
| 05:57
|5. Understand the concept of packing and unpacking tuples.
+
 
+
|-
+
| 5:57
+
 
| Here are some self assessment questions for you to solve.
 
| Here are some self assessment questions for you to solve.
  
 
|-
 
|-
|6:01
+
|06:01
|1. Define a tuple containing two values.  
+
|Define a tuple containing two values.  
  
 
|-
 
|-
|6:04
+
|06:04
 
|The first being integer 4 and second is a float 2.5
 
|The first being integer 4 and second is a float 2.5
  
 
|-
 
|-
|6:08
+
|06:08
|2. If a = 5,  then what is the type of a ?
+
|If a = 5,  then what is the type of a ?
  
 
|-
 
|-
|6:13
+
|06:13
 
|The options are int , float, tuple, string.
 
|The options are int , float, tuple, string.
  
 
|-
 
|-
|6:19
+
|06:19
 
|The final question the third one is if  a = (2, 3)  
 
|The final question the third one is if  a = (2, 3)  
  
 
|-
 
|-
|6:25
+
|06:25
 
| What does  a[0], a[1] = (3, 4)  produce.
 
| What does  a[0], a[1] = (3, 4)  produce.
  
 
|-
 
|-
| 6:34
+
| 06:34
 
| And the answers,
 
| And the answers,
  
 
|-
 
|-
|6:38
+
|06:38
|1. A tuple is defined by enclosing parentheses around a sequence of items separated by commas.  
+
|A tuple is defined by enclosing parentheses around a sequence of items separated by commas.  
  
 
|-
 
|-
|6:44
+
|06:44
 
|Hence, we write our tuple as,within brackets 4 comma 2.5.
 
|Hence, we write our tuple as,within brackets 4 comma 2.5.
  
 
|-
 
|-
|6:53
+
|06:53
|2. Since the given data is 5 followed by a comma, it means that it is a tuple
+
|Since the given data is 5 followed by a comma, it means that it is a tuple
  
 
|-
 
|-
|7:01
+
|07:01
|3.  The operation a in square brackets 0, a in square brackets 1 is equal to in brackets 3 comma 4 will result in an error because tuples are immutable.  
+
|The operation a in square brackets 0, a in square brackets 1 is equal to in brackets 3 comma 4 will result in an error because tuples are immutable.  
 
+
  
 
|-
 
|-
7:14
+
07:14
 
| Hope you have enjoyed this tutorial and found it useful.  
 
| Hope you have enjoyed this tutorial and found it useful.  
  
 
|-
 
|-
|7:17
+
|07:17
 
|Thank you!
 
|Thank you!
  
 
|}
 
|}

Latest revision as of 12:34, 27 March 2017

Time Narration
00:00 Hello friends and welcome to the tutorial on "getting started with tuples".
00:05 At the end of the tutorial, you will be able to,

Understand of what tuples are. Compare them with lists. Know why they are needed and where to use them.

00:15 Before beginning this tutorial,we would suggest you to complete the tutorial on "Getting started with lists".
00:21 Let us start our ipython interpreter.
00:23 Type ipython and hit Enter.
00:27 Let's get started by defining a tuple.
00:29 A tuple is defined by enclosing parentheses around a sequence of items separated by commas.
00:39 It is similar to defining a list except that parentheses are used instead of square brackets.
00:45 So type t is equal to within brackets 1, 2.5, "hello",-4, "world", 1.24,5.
01:02 The items in the tuple are indexed using numbers and can be accessed by using their position.
01:10 For example,First you must type t
01:18 Then type t within square brackets 3.
01:24 It prints -4 which is the fourth item of the tuple.
01:29 Similarly type t within square brackets 1 colon 5 colon 2 and hit Enter.
01:40 It prints the corresponding slice.
01:42 This behaviour is similar to that of lists.
01:46 But the difference can be seen when we try to change an element in the tuple.
01:51 So type t within square brackets 2 is equal to in double quotes Hello, H is capital.
02:05 We can see that, it raises an error saying 'tuple object does not support item assignment'.
02:10 Tuples are immutable, and hence cannot be changed after creation.
02:13 Then, what is the use of tuples?
02:16 We shall understand that soon.
02:19 But let us look at a simple problem of swapping values.
02:24 Pause the video here, try out the following exercise and resume the video.
02:30 Given, a is equal to 5 and b is equal to 7.
02:33 Swap the values of a and b.
02:38 Switch to terminal for solution
02:40 Type a is equal to 5, then b is equal to 7 , then type a and then b, you can see the values.
02:50 We now create a variable say, temp and swap the values using this variable.
02:56 So type temp is equal to a.Then a is equal to b ;then type b is equal to temp.
03:08 Then type a.
03:10 Then b.
03:13 This is the traditional approach
03:16 So let us do it the python way.
03:21 So type a; then b; then a comma b is equal to b comma a.
03:33 then a ; then b to see the output.
03:38 We see that the values are swapped.
03:43 This idiom works for different data-types also.
03:46 So lets type a is equal to 2 point 5; then b within double quotes hello where h is small letter.
03:59 Then a comma b is equal to b comma a.
04:09 Then a; then b.
04:13 Moreover this type of behavior is something that feels natural and you'd expect to happen.
04:19 This is possible because of the immutability of tuples.
04:22 This process is called tuple packing and unpacking.
04:26 So type 5 comma to see what is tuple packing
04:37 What we see in the tuple is 1 element.
04:41 So type 5 comma within double quotes hello where h is small letter comma 2.5.
04:57 Now, It is a tuple with 3 elements.
05:03 So when we are actually typing 2 or more elements separated by comma the elements are packed into a tuple.
05:10 When we type a comma b is equal to b comma a first the value of b and a are packed into a tuple from the right side then unpack into the variables a and b.
05:21 Immutability of tuples ensure that values are not changed during the packing and unpacking.
05:29 So This brings us to the end of this tutorial.
05:33 In this tutorial, we have learn't to,
05:35 Define tuples.Understand the similarities of tuples with lists, like indexing and iterability.
05:44 Know about the immutability of tuples.
05:48 Swap values, the python way.
05:52 Understand the concept of packing and unpacking tuples.
05:57 Here are some self assessment questions for you to solve.
06:01 Define a tuple containing two values.
06:04 The first being integer 4 and second is a float 2.5
06:08 If a = 5, then what is the type of a ?
06:13 The options are int , float, tuple, string.
06:19 The final question the third one is if a = (2, 3)
06:25 What does a[0], a[1] = (3, 4) produce.
06:34 And the answers,
06:38 A tuple is defined by enclosing parentheses around a sequence of items separated by commas.
06:44 Hence, we write our tuple as,within brackets 4 comma 2.5.
06:53 Since the given data is 5 followed by a comma, it means that it is a tuple
07:01 The operation a in square brackets 0, a in square brackets 1 is equal to in brackets 3 comma 4 will result in an error because tuples are immutable.
07:14 Hope you have enjoyed this tutorial and found it useful.
07:17 Thank you!

Contributors and Content Editors

Gaurav, Minal, PoojaMoolya, Sneha