<?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-3.4.3%2FC3%2FGetting-started-with-for%2FEnglish-timed</id>
		<title>Python-3.4.3/C3/Getting-started-with-for/English-timed - 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-3.4.3%2FC3%2FGetting-started-with-for%2FEnglish-timed"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python-3.4.3/C3/Getting-started-with-for/English-timed&amp;action=history"/>
		<updated>2026-04-10T04:02:49Z</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-3.4.3/C3/Getting-started-with-for/English-timed&amp;diff=47633&amp;oldid=prev</id>
		<title>PoojaMoolya: Created page with &quot; {| border=1 |  &lt;center&gt;'''Time'''&lt;/center&gt; |  &lt;center&gt;'''Narration'''&lt;/center&gt;  |- | 00:01 |  Hello Friends. Welcome to the tutorial on &quot;Getting started with '''for loops'''&quot;...&quot;</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python-3.4.3/C3/Getting-started-with-for/English-timed&amp;diff=47633&amp;oldid=prev"/>
				<updated>2019-05-30T10:55:45Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot; {| border=1 |  &amp;lt;center&amp;gt;&amp;#039;&amp;#039;&amp;#039;Time&amp;#039;&amp;#039;&amp;#039;&amp;lt;/center&amp;gt; |  &amp;lt;center&amp;gt;&amp;#039;&amp;#039;&amp;#039;Narration&amp;#039;&amp;#039;&amp;#039;&amp;lt;/center&amp;gt;  |- | 00:01 |  Hello Friends. Welcome to the tutorial on &amp;quot;Getting started with &amp;#039;&amp;#039;&amp;#039;for loops&amp;#039;&amp;#039;&amp;#039;&amp;quot;...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
{| border=1&lt;br /&gt;
|  &amp;lt;center&amp;gt;'''Time'''&amp;lt;/center&amp;gt;&lt;br /&gt;
|  &amp;lt;center&amp;gt;'''Narration'''&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 00:01&lt;br /&gt;
|  Hello Friends. Welcome to the tutorial on &amp;quot;Getting started with '''for loops'''&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:08&lt;br /&gt;
|  At the end of this tutorial, you will be able to,&lt;br /&gt;
&lt;br /&gt;
Use the '''for loop'''.&lt;br /&gt;
&lt;br /&gt;
Use '''range() function'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:17&lt;br /&gt;
|  To record this tutorial, I am using,&lt;br /&gt;
&lt;br /&gt;
'''Ubuntu Linux 14.04''' operating system&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:25&lt;br /&gt;
| '''Python 3.4.3''' and '''IPython 5.1.0'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:32&lt;br /&gt;
|  To practice this tutorial, you should know how to use '''lists'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:37&lt;br /&gt;
|  If not, see the relevant '''Python''' tutorials on this website.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:42&lt;br /&gt;
|  First let us see the syntax of '''for loop'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:46&lt;br /&gt;
|'''for statement''' iterates over the members of a sequence in order, executing the '''block''' each time.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  00:54&lt;br /&gt;
|  Here the '''loop variable''' takes the value of the '''item''' inside the sequence on each iteration.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:01&lt;br /&gt;
| For each '''item,''' the '''loop body''' is executed. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:05&lt;br /&gt;
| We will see an example of '''for loop''' and how to execute it.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:10&lt;br /&gt;
| Let us first open the '''Terminal '''by pressing '''Ctrl+Alt+T '''keys simultaneously. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:17&lt;br /&gt;
| Now, type '''ipython3''' and press '''Enter'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:22&lt;br /&gt;
| Let us initialise the '''pylab package'''.&lt;br /&gt;
&lt;br /&gt;
Type '''%pylab '''and press''' Enter.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  01:30&lt;br /&gt;
|  Open your '''text editor'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  01:33&lt;br /&gt;
|  Let us write a '''for loop'''. Type the code as shown here:&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  01:39&lt;br /&gt;
|  Here the loop variable iterates over a list of numbers and finds the square root of each number. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 01:46&lt;br /&gt;
| The numbers are: 4, 9, 16, 25, and 36.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  01:52&lt;br /&gt;
|  Note that here we used two variables, '''numbers ''' which is a '''list''' of numbers&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:00&lt;br /&gt;
| '''num''' - which is the element of '''list''' under consideration, in each cycle of the '''for loop'''. &lt;br /&gt;
&lt;br /&gt;
The variable names can be any of your choice.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:11&lt;br /&gt;
| Note that a '''colon''' after the '''for statement''' indicates the starting of '''loop body'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:18&lt;br /&gt;
| Every '''statement '''in '''loop''' starts with 4 spaces.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:24&lt;br /&gt;
| It means that, the line is a '''block''' of '''code''' in '''for loop'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:29&lt;br /&gt;
|In this example, it is only a single '''statement''' in the '''block'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  02:35&lt;br /&gt;
|  Note that the line '''print(&amp;quot;This is outside for-loop&amp;quot;)''' is not indented. &lt;br /&gt;
&lt;br /&gt;
It means that it is not a part of the''' for loop'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  02:46&lt;br /&gt;
| And the lines after that don't fall in the scope of the '''for loop'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 02:51&lt;br /&gt;
|  Thus each '''block''' is separated by the indentation level. &lt;br /&gt;
&lt;br /&gt;
This marks the importance of '''white-spaces''' in '''Python'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  03:01&lt;br /&gt;
|  Save the file as '''sqrt_num_list.py '''in the''' home directory'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:13&lt;br /&gt;
| Now switch back to your '''terminal'''.&lt;br /&gt;
&lt;br /&gt;
Let us clear the '''terminal'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:19&lt;br /&gt;
|  Run the script using the '''run''' command as '''''percent'' run ''minus'' i filename '''and press '''Enter.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  03:31&lt;br /&gt;
|  We get the square root of the given numbers executed by the '''for loop'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:37&lt;br /&gt;
| This is the '''print statement''' output executed after the '''for loop'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:42&lt;br /&gt;
| Use the same example we used in '''sqrt_num_list.py'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:48&lt;br /&gt;
| Type each line of the code in the '''IPython interpreter prompt. '''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:53&lt;br /&gt;
| Skip the line: '''print(&amp;quot;This is outside for-loop&amp;quot;)'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 03:58&lt;br /&gt;
| Switch to the '''terminal'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:01&lt;br /&gt;
| Type,'''numbers ''equal to inside square brackets'' 4, 9, 16, 25, 36''' and press '''Enter'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:20&lt;br /&gt;
|  '''for num in numbers '''''colon'' Press '''Enter'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:27&lt;br /&gt;
|  You will notice that, the '''prompt''' changes to three dots. &lt;br /&gt;
&lt;br /&gt;
And the cursor is not after the three dots but, there are four spaces from the three dots.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:40&lt;br /&gt;
|  Please note that '''IPython''' automatically indents the '''block'''. &lt;br /&gt;
&lt;br /&gt;
The three dots tell you that you are inside a '''block'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  04:50&lt;br /&gt;
|  Now type the rest of the '''for loop'''. &lt;br /&gt;
&lt;br /&gt;
'''print ''inside parentheses inside quotes sqrt of comma ''num ''comma inside quotes is comma'' num ''asterick asterick which is raised to power of'' 0.5''' and press '''Enter'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:19&lt;br /&gt;
| Now we have finished the '''statements''' in the '''block'''.&lt;br /&gt;
&lt;br /&gt;
But still the '''interpreter''' is showing three dots. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:26&lt;br /&gt;
| This means that you are still inside the '''block'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  05:30&lt;br /&gt;
| To exit from the '''block''', press '''Enter''' key twice without entering anything else.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:37&lt;br /&gt;
| It printed the square root of each number in the '''list''', which was executed in the '''for loop.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 05:44&lt;br /&gt;
| Next we will see about '''range built-in function''' in '''Python'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  05:48&lt;br /&gt;
|  '''range()''' function generates a '''list''' of '''integers.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  05:52&lt;br /&gt;
| The syntax is: '''range  start ''comma'' stop ''comma'' step''' &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  05:59&lt;br /&gt;
| For example: '''range ''inside parentheses'' one ''comma'' twenty ''comma'' two ''' generates integers from 1 to 19 with step of 2&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:11&lt;br /&gt;
|  '''range ''inside parentheses'' twenty ''' generates integers from 0 to 19&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:18&lt;br /&gt;
|  Note that the ending number that you specify will not be included in the '''list'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 06:25&lt;br /&gt;
| Find out the cube of all the numbers from one to ten.&lt;br /&gt;
&lt;br /&gt;
Execute this in the '''Python interpreter'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  06:34&lt;br /&gt;
|  Let us now try to run the '''for loop''' in a '''Python terminal''' window.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  06:40&lt;br /&gt;
|  Open a new '''terminal''' by  pressing '''Ctrl+Alt+T''' keys simultaneously.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  06:46&lt;br /&gt;
|Start the '''Python interpreter''' by issuing the '''command python '''in the new '''terminal''' and press '''Enter'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  06:54&lt;br /&gt;
|  Type, '''for i '''in range '''''inside parentheses'' one ''comma ''eleven ''colon'' and '''press '''Enter'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  07:06&lt;br /&gt;
|  We will see that this time it shows three dots, but the cursor is close to the dots. &lt;br /&gt;
&lt;br /&gt;
So we have to indent the '''block'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:17&lt;br /&gt;
|  The '''Python interpreter''' does not indent the code automatically. &lt;br /&gt;
&lt;br /&gt;
So enter four '''spaces''' and then type the following.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  07:27&lt;br /&gt;
|  '''print ''inside parentheses'' i ''comma inside quotes ''cube is ''comma'' i ''raised to power of'' three''' press '''Enter'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 07:44&lt;br /&gt;
|  Now when we hit '''Enter''', we still see the three dots. &lt;br /&gt;
&lt;br /&gt;
To get out of the '''block''', press '''Enter''' once again.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  07:53&lt;br /&gt;
|  Okay!   So the main thing we learnt here is - how to use the '''Python interpreter''' and &lt;br /&gt;
&lt;br /&gt;
the '''IPython interpreter''' to specify '''blocks'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 08:03&lt;br /&gt;
| Print all the odd numbers from 1 to 50.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  08:07&lt;br /&gt;
| Let us do it in our '''IPython interpreter''' for ease of use.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 08:12&lt;br /&gt;
| The problem can be solved by just using the '''range() function'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 08:17&lt;br /&gt;
| Let us clear the '''terminal'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  08:20&lt;br /&gt;
|  for''' i ''in range inside parentheses'' one ''comma'' fifty ''comma'' two ''colon '''&lt;br /&gt;
&lt;br /&gt;
press '''Enter '''&lt;br /&gt;
&lt;br /&gt;
'''print'' inside parentheses'' i''' press '''Enter '''twice.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 08:40&lt;br /&gt;
| The first '''parameter''' is the starting number of the sequence.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 08:45&lt;br /&gt;
| The second '''parameter''' is the end of the '''range'''. &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 08:49&lt;br /&gt;
| Note that the '''sequence''' does not include the ending number. &lt;br /&gt;
&lt;br /&gt;
The third '''parameter''' is for stepping through the '''sequence'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 08:59&lt;br /&gt;
| Here we gave '''two''' which means we are skipping every alternate '''element'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 09:05&lt;br /&gt;
| This brings us to the end of the tutorial. &lt;br /&gt;
&lt;br /&gt;
In this tutorial, we learnt to, Create '''blocks''' in '''python''' using''' for'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  09:15&lt;br /&gt;
| Indent the '''blocks''' of code&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  09:17&lt;br /&gt;
| Iterate over a list using '''for loop''' and  Use the '''range() function'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 09:23&lt;br /&gt;
| Here are some self assessment questions for you to solve&lt;br /&gt;
&lt;br /&gt;
Indentation is not mandatory in '''Python'''&lt;br /&gt;
&lt;br /&gt;
True or  False&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  09:32&lt;br /&gt;
| Write a '''for loop''' to print the product of all natural numbers from 1 to 20.&lt;br /&gt;
&lt;br /&gt;
What will be the output of: '''range(1, 5)'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 09:43&lt;br /&gt;
| And the answers,&lt;br /&gt;
&lt;br /&gt;
1. False, '''Indentation''' is essential in '''python'''.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 09:51&lt;br /&gt;
|  2. '''y '''''equal to''''' one'''&lt;br /&gt;
&lt;br /&gt;
'''for x in range ''' one '''''comma''''' twenty one''''' &lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 09:58&lt;br /&gt;
|  '''y''''' into equal to''''' x'''&lt;br /&gt;
&lt;br /&gt;
'''print y'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 10:03&lt;br /&gt;
| 3. '''range(1, 5)''' will produce a list of integers from 1 to 4 i.e. [1,2,3,4]&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 10:14&lt;br /&gt;
| Please post your timed queries in this forum.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 10:18&lt;br /&gt;
| Please post your general queries on Python in this forum.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 10:23&lt;br /&gt;
| FOSSEE team coordinates the TBC project.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 10:27&lt;br /&gt;
| Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India.&lt;br /&gt;
&lt;br /&gt;
For more details, visit this website.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 10:37&lt;br /&gt;
| This is Trupti Kini from IIT Bombay signing off.&lt;br /&gt;
&lt;br /&gt;
Thank you.&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>PoojaMoolya</name></author>	</entry>

	</feed>