Interactive Mode of Python 2.7


Interactive Mode of Python 2.7


What we see is a welcome message of Python interpreter with revision details and the Python prompt, i.e., „>>>. This is a primary prompt indicating that the interpreter is expecting a python command. There is secondary prompt also which is „… indicating that interpreter is waiting for additional input to complete the current statement.

Interpreter uses prompt to indicate that it is ready for instruction. Therefore, we can say, if there is prompt on screen, it means IDLE is working in interactive mode. We type Python expression / statement / command after the prompt and Python immediately responds with the output of it. Lets start with typing print “How are you” after the prompt.

>>>print “How are you?”

How are you?

What we get is Pythons response. We may try the following and check the response:

i) print 5+7
ii) 5+7
iii) 6*250/9
iv) print 5-7
It is also possible to get a sequence of instructions executed through interpreter.

Example 1
>>> x=2
>>> y=6
>>> z = x+y
>>> print z
8

Example 2
>>> a=3
>>> a+1, a-1
(4,2) #result is tuple of 2 values

#result is tuple of 2 values, is a comment statement. We will talk about it in the later
part.

Now we are good to write a small code on our own in Python.

NOTE: While writing in Python, remember Python is case sensitive. That means x & X are different in Python.

To Exit from Interactive Mode:
^D (Ctrl+D) or quit () is used to leave the interpreter.
^F6 will restart the shell.

NOTE : ^ means Control key.

Comments

Popular posts from this blog

Python Introduction

Script Mode