<?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%2FI-O%2FEnglish</id>
		<title>Python/C3/I-O/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%2FI-O%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python/C3/I-O/English&amp;action=history"/>
		<updated>2026-05-15T03:51:56Z</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/I-O/English&amp;diff=493&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 this tutorial on …'</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python/C3/I-O/English&amp;diff=493&amp;oldid=prev"/>
				<updated>2012-11-29T06:14:11Z</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 this tutorial on …&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 this tutorial on 'Input/Output'.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 2 &lt;br /&gt;
&lt;br /&gt;
Learning objectives &lt;br /&gt;
| At the end of this tutorial,you will be able to,&lt;br /&gt;
&lt;br /&gt;
# Print some value.&lt;br /&gt;
# Print using modifiers.&lt;br /&gt;
# Take input from user.&lt;br /&gt;
# Display a prompt to the user before taking the input.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  ipython&lt;br /&gt;
| Let us first start ipython on our terminal&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  a = &amp;quot;This is a string&amp;quot;&lt;br /&gt;
 a&lt;br /&gt;
 print a&lt;br /&gt;
| Let us start this tutorial by typing a string&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  b = &amp;quot;A line \n New line&amp;quot;&lt;br /&gt;
 b&lt;br /&gt;
 print b&lt;br /&gt;
| &amp;lt;tt&amp;gt;print a&amp;lt;/tt&amp;gt;, obviously, prints the value of &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
As you can see, even when you type just a, the value of a is shown. But there is a difference.&lt;br /&gt;
&lt;br /&gt;
Typing just &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; displays the content of &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt; whereas the statement &amp;lt;tt&amp;gt;print a&amp;lt;/tt&amp;gt; prints the string itself. This difference becomes more evident when we use strings with newlines in them.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  x = 1.5&lt;br /&gt;
 y = 2&lt;br /&gt;
 z = &amp;quot;red&amp;quot;&lt;br /&gt;
 print &amp;quot;x is %2.1f, y is %d, z is %s&amp;quot;%(x,y,z)&lt;br /&gt;
| As you can see, just typing &amp;lt;tt&amp;gt;b&amp;lt;/tt&amp;gt; shows that b contains a newline character but While typing &amp;lt;tt&amp;gt;print b&amp;lt;/tt&amp;gt;,it prints the string and hence the newline.&lt;br /&gt;
&lt;br /&gt;
Moreover when we type just &amp;lt;tt&amp;gt;a&amp;lt;/tt&amp;gt;, the value a is shown only in interactive mode and does not have any effect on the program while running it as a script.&lt;br /&gt;
&lt;br /&gt;
We shall look at different ways of outputting the data.&lt;br /&gt;
&lt;br /&gt;
print statement in python supports string formatting. Various arguments can be passed to print using modifiers.&lt;br /&gt;
&lt;br /&gt;
type&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
| As you can see, the values of x, y and z are substituted in place of the modifiers &amp;lt;tt&amp;gt;%2.1f&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;%d&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;%s&amp;lt;/tt&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
Pause the video here, try out the following exercise and resume the video.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 3 &lt;br /&gt;
&lt;br /&gt;
Assignment 1 &lt;br /&gt;
| What happens when you do &amp;lt;tt&amp;gt;print &amp;quot;x is %d, y is %f&amp;quot; %(x, y)&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Continue from paused state Switch to the terminal &lt;br /&gt;
&lt;br /&gt;
 print &amp;quot;x is %d, y is %f&amp;quot; %(x, y)&lt;br /&gt;
| Switch to the terminal for solution.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| open an editor &lt;br /&gt;
&lt;br /&gt;
 print &amp;quot;Hello&amp;quot;&lt;br /&gt;
 print &amp;quot;World&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 print &amp;quot;Hello&amp;quot;,&lt;br /&gt;
 print &amp;quot;World&amp;quot;&lt;br /&gt;
| We see that the &amp;lt;tt&amp;gt;int&amp;lt;/tt&amp;gt; value of x and &amp;lt;tt&amp;gt;float&amp;lt;/tt&amp;gt; value of y are printed corresponding to the modifiers used in the print statement.&lt;br /&gt;
&lt;br /&gt;
We have seen that &amp;lt;tt&amp;gt;print&amp;lt;/tt&amp;gt; statement prints a new line character everytime it is called. This can be suppressed by using a &amp;quot;,&amp;quot; at the end of the &amp;lt;tt&amp;gt;print&amp;lt;/tt&amp;gt; statement.&lt;br /&gt;
&lt;br /&gt;
Let us see this by typing out following code on an editor as print_example.py&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  ip = raw_input()&lt;br /&gt;
| Save the script as 'print_example.py' and run it using %run /home/fossee/print_example.py&lt;br /&gt;
&lt;br /&gt;
As we can see, the print statement when used with comma in the end, prints a space instead of a new line.&lt;br /&gt;
&lt;br /&gt;
Now we shall look at taking input from the user. We will use the ~~raw_input~~ for this. type&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  an input&lt;br /&gt;
| The cursor is blinking indicating that it is waiting for input type something and hit enter.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  ip&lt;br /&gt;
| Now let us see what is the value of ip by typing it.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
| We can see that it contains the string &amp;quot;an input&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Pause the video here, try out the following exercise and resume the video.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 4 &lt;br /&gt;
&lt;br /&gt;
Assignment 2 &lt;br /&gt;
| Enter the number 5.6 as input and store it in a variable called c.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Continue from paused state Switch to the terminal &lt;br /&gt;
| Switch to the terminal for solution.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  c = raw_input()&lt;br /&gt;
 5.6&lt;br /&gt;
 c&lt;br /&gt;
| We have to use the raw_input command with variable c. type&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  type(c)&lt;br /&gt;
| Now let us see the type of c.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
| We see that c is a string. This implies that anything you enter as input, it will be taken as a string no matter what you enter.&lt;br /&gt;
&lt;br /&gt;
Pause the video here, try out the following exercise and resume the video.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 5 &lt;br /&gt;
&lt;br /&gt;
Assignment 3 &lt;br /&gt;
| What happens when you do not enter anything and hit enter.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Continue from paused state Switch to the terminal &lt;br /&gt;
&lt;br /&gt;
 d = raw_input()&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;RET&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 d&lt;br /&gt;
| Switch to the terminal for solution.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|  name = raw_input(&amp;quot;Please enter your name: &amp;quot;)&lt;br /&gt;
| We see that when nothing is entered, an empty string is considered as input.&lt;br /&gt;
&lt;br /&gt;
raw_input also can display a prompt to assist the user.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
| It prints the string given as argument and then waits for the user input.&lt;br /&gt;
&lt;br /&gt;
Let us do one more exercise. Pause the video here, try out the following exercise and resume the video.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 6 &lt;br /&gt;
&lt;br /&gt;
Assignment 4 &lt;br /&gt;
| How do you display a prompt and let the user enter input in next line.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Continue from paused state Switch to the terminal &lt;br /&gt;
&lt;br /&gt;
 ip = raw_input(&amp;quot;Please enter a number in the next line\n&amp;gt; &amp;quot;)&lt;br /&gt;
| Switch to the terminal for solution. The trick is to include a newline character at the end of the prompt string.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
| It prints the newline character and hence the user enters input in the next line&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 7 &lt;br /&gt;
&lt;br /&gt;
Summary slide &lt;br /&gt;
| This brings us to the end of the tutorial. In this tutorial, we have learnt to,&lt;br /&gt;
&lt;br /&gt;
# Use the print statement.&lt;br /&gt;
# Use the modifiers %d, %f, %s in the print statement.&lt;br /&gt;
# Take input from user by using &amp;lt;tt&amp;gt;raw_input()&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Display a prompt to the user before taking the input by passing a string as an argument to &amp;lt;tt&amp;gt;raw_input&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 8 &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;
# &amp;lt;tt&amp;gt;a = raw_input()&amp;lt;/tt&amp;gt; and user enters &amp;lt;tt&amp;gt;2.5&amp;lt;/tt&amp;gt;. What is the type of a?&lt;br /&gt;
** str&lt;br /&gt;
** int&lt;br /&gt;
** float&lt;br /&gt;
** char&lt;br /&gt;
# &amp;lt;tt&amp;gt;'''a = 2&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;b = 4.5&amp;lt;/tt&amp;gt;. What does ``print &amp;quot;a is %d and b is'''&amp;lt;br/&amp;gt; Inline literal start-string without end-string.&amp;lt;br/&amp;gt; %2.1f&amp;quot; %(b, a)`` print?&lt;br /&gt;
** a is 2 and b is 4.5&lt;br /&gt;
** a is 4 and b is 2&lt;br /&gt;
** a is 4 and b is 2.0&lt;br /&gt;
** a is 4.5 and b is 2&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 9 &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;
# No matter what you enter, it will be taken as a string. Hence 2.5 is a string.&lt;br /&gt;
# Since 'b' is called first, It will display integer value of 'a' because the modifier used is %d. Similarly, 'b' will get the float value of 'a' due to it's modifier %2.1f. Hence 'a' will be 4 and 'b' 2.0 .&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| Show Slide 10 &lt;br /&gt;
&lt;br /&gt;
Acknowledgment slide &lt;br /&gt;
| Hope you have enjoyed this tutorial and found it useful. Thank You!&lt;br /&gt;
&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Chandrika</name></author>	</entry>

	</feed>