<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Python%2FC3%2FGetting-started-with-lists%2FEnglish</id>
		<title>Python/C3/Getting-started-with-lists/English - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Python%2FC3%2FGetting-started-with-lists%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python/C3/Getting-started-with-lists/English&amp;action=history"/>
		<updated>2026-05-15T02:44:17Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Python/C3/Getting-started-with-lists/English&amp;diff=475&amp;oldid=prev</id>
		<title>Chandrika: Created page with '{| border=1 !Visual Cue !Narration |- | Show Slide 1   Containing title, name of the production team along with the logo of MHRD  | Hello friends and welcome to the tutorial on &quot;…'</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python/C3/Getting-started-with-lists/English&amp;diff=475&amp;oldid=prev"/>
				<updated>2012-11-29T06:06:23Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;{| border=1 !Visual Cue !Narration |- | Show Slide 1   Containing title, name of the production team along with the logo of MHRD  | Hello friends and welcome to the tutorial on &amp;quot;…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{| border=1&lt;br /&gt;
!Visual Cue&lt;br /&gt;
!Narration&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 1 &lt;br /&gt;
&lt;br /&gt;
Containing title, name of the production team along with the logo of MHRD &lt;br /&gt;
| Hello friends and welcome to the tutorial on &amp;quot;Getting started with lists&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 2 &lt;br /&gt;
&lt;br /&gt;
Learning objectives &lt;br /&gt;
| In this tutorial we will be getting acquainted with a python data structure called lists. At the end of this tutorial, you will be able to,&lt;br /&gt;
&lt;br /&gt;
# Create lists&lt;br /&gt;
# Access list elements&lt;br /&gt;
# Append elements to lists&lt;br /&gt;
# Delete elements from lists&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  ipython&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;empty = []&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 type(empty)&lt;br /&gt;
| List is a compound data type, it can contain data of mutually different data types. List is also a sequence data type where all the elements are arranged in a specific order.&lt;br /&gt;
&lt;br /&gt;
Start the ipython interpreter and first create an empty list with no elements.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;nowiki&amp;gt;nonempty = ['spam', 'eggs', 100, 1.234]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| This is an empty list without any elements.&lt;br /&gt;
&lt;br /&gt;
Lets define a non-empty list as:&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;nowiki&amp;gt;listinlist=[[4,2,3,4],'and', 1, 2, 3, 4]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| Thus, the simplest way of creating a list is typing out a sequence of comma-separated values (or items) between two square brackets.&lt;br /&gt;
&lt;br /&gt;
As we can see, lists can contain different kinds of data. In the previous example 'spam' and 'eggs' are strings whereas 100 and 1.234 are integer and float respectively. Thus, we can put elements of different data types in lists including lists itself. This property makes lists heterogeneous data structures.&lt;br /&gt;
&lt;br /&gt;
Let us include a list within a list.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;nowiki&amp;gt;nonempty[0]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;nonempty[1]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;nonempty[3]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| &amp;lt;nowiki&amp;gt;We access an element of a list using its corresponding index. Index of the first element of a list is 0. So for the list nonempty, nonempty[0] gives the first element, nonempty[1] the second element and so on and nonempty[3] the last element.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 3 &lt;br /&gt;
&lt;br /&gt;
Assignment 1 &lt;br /&gt;
| Pause the video here, try out the following exercise and resume the video.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;What happens when you do nonempty[-1].&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Switch to the terminal &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;nonempty[-1]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| As you can see you get the last element which is 1.234.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;nowiki&amp;gt;nonempty[-2]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;nonempty[-4]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| In python negative indices are used to access elements from the end. -1 gives the last element which is the 4th element , -2 gives second element to last and -4 gives the fourth from the last which, in this case, is the first element.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  nonempty.append('onemore')&lt;br /&gt;
 nonempty&lt;br /&gt;
 nonempty.append(6)&lt;br /&gt;
 nonempty&lt;br /&gt;
| We can also append elements to the end of a list using the &amp;lt;tt&amp;gt;append&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 4&lt;br /&gt;
&lt;br /&gt;
Assignment 2 &lt;br /&gt;
| Please, pause the video here. Do the exercise and then continue.&lt;br /&gt;
&lt;br /&gt;
# What is the syntax to get the element 'and' in the list,listinlist ?&lt;br /&gt;
# How would you get 'and' using negative indices?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 5 &lt;br /&gt;
&lt;br /&gt;
Solution 2 &lt;br /&gt;
| The solution is on your screen&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;listinlist[1] listinlist[-5]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As we can see nonempty is appended with 'onemore' and 6 at the end.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  len(nonempty)&lt;br /&gt;
| Let us move further. We can use &amp;lt;tt&amp;gt;len&amp;lt;/tt&amp;gt; function to check the number of elements in the list. Let us find out the length of the list 'nonempty'.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;nowiki&amp;gt;del(nonempty[1])&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| Just like we can append elements to a list, we can also remove them. There are two ways of doing it. One is by using index.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  nonempty.remove(100)&lt;br /&gt;
| The function &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt; deletes the element at index 1, i.e the second element of the list, 'eggs'.&lt;br /&gt;
&lt;br /&gt;
The other way is removing element by content. Lets say one wishes to delete 100 from nonempty list.For this, one could use the function &amp;lt;tt&amp;gt;remove&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  nonempty.append('spam')&lt;br /&gt;
 nonempty&lt;br /&gt;
 nonempty.remove('spam')&lt;br /&gt;
 nonempty&lt;br /&gt;
| But what if there were two 100's. To check that lets do a small experiment.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
| If we now check, we will see that the first occurence 'spam' is removed and therefore the function ''remove'' removes the first occurence of the element in the sequence and leaves others untouched.&lt;br /&gt;
&lt;br /&gt;
One should remember this, that while &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt; removes by index number, ''remove'' removes on the basis of content being passed on. Let us take an example.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;nowiki&amp;gt;k = [1,2,1,3]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;del([k[2])&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
| &amp;lt;nowiki&amp;gt;del gives us [1,2,3].&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  &amp;lt;nowiki&amp;gt;k.remove(k[2])&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 k&lt;br /&gt;
| &amp;lt;nowiki&amp;gt;remove will give us [2,1,3]. Since it deletes the first occurrence of what is returned by k[2] which is 1.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 6&lt;br /&gt;
&lt;br /&gt;
Assignment 3 &lt;br /&gt;
| Pause the video here, try out the following exercise and resume the video.&lt;br /&gt;
&lt;br /&gt;
# Remove the third element from the list, listinlist.&lt;br /&gt;
# Remove 'and' from the list, listinlist.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 7 &lt;br /&gt;
&lt;br /&gt;
Assignment 3 &lt;br /&gt;
| The solution is on your screen.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;del(listinlist[2]) listinlist.remove('and')&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 8&lt;br /&gt;
&lt;br /&gt;
Summary &lt;br /&gt;
| This brings us to the end of this tutorial. In this tutorial, we have learnt to,&lt;br /&gt;
&lt;br /&gt;
# Create lists.&lt;br /&gt;
# Access lists using their index numbers.&lt;br /&gt;
# Append elements to list using the function &amp;lt;tt&amp;gt;append&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Delete Element from lists by specifying the index number of the element to be deleted in the &amp;lt;tt&amp;gt;del&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# Delete element from list by content using &amp;lt;tt&amp;gt;remove&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# Find out the list length using &amp;lt;tt&amp;gt;len&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 9&lt;br /&gt;
&lt;br /&gt;
Self assessment questions slide&lt;br /&gt;
| Here are some self assessment questions for you to solve&lt;br /&gt;
&lt;br /&gt;
# How do you create an empty list?&lt;br /&gt;
# Can you have a list inside a list ?&lt;br /&gt;
# How would you access the end of a list without finding its length?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 10&lt;br /&gt;
&lt;br /&gt;
Solution of self assessment questions on slide &lt;br /&gt;
| And the answers,&lt;br /&gt;
&lt;br /&gt;
# We create an empty list just by leaving the space inside the square brackets empty.&amp;lt;br/&amp;gt;  &amp;lt;nowiki&amp;gt;empty=[]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# Yes.List can contain all the other data types, including list. Here is an example&amp;lt;br/&amp;gt;  &amp;lt;nowiki&amp;gt;list_in_list=[2.3,[2,4,6],'string,'all datatypes can be there']&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
# Using negative indices, we can access the list from the end using negative indices. This is an example&amp;lt;br/&amp;gt;  &amp;lt;nowiki&amp;gt;nonempty = ['spam', 'eggs', 100, 1.234]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;nonempty[-1]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 11 &lt;br /&gt;
&lt;br /&gt;
Acknowledgment Slide &lt;br /&gt;
| Hope you have enjoyed this tutorial and found it useful. Thank you!&lt;/div&gt;</summary>
		<author><name>Chandrika</name></author>	</entry>

	</feed>