Friday, 4 December 2015

Python interactive command line

Open command prompt (or) terminal and type ‘python3’ command. It opens python interactive session.
$ python3
Python 3.5.0 (v3.5.0:374f501f4567, Sep 12 2015, 11:00:19) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

How to exit from python interpreter
On Windows, a Ctrl-Z gets you out of this session; on Unix, try Ctrl-D instead. Another way is simply call the quit() function to quit from python.
$ python3
Python 3.5.0 (v3.5.0:374f501f4567, Sep 12 2015, 11:00:19) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
$ 


You can type any statement (or) expressions in python interpreter, interpreter execute those statements and gives you the result.
>>> 10+20
30
>>> 20*20
400
>>> print('Hello World')
Hello World


Note:
On Unix, the Python 3.x interpreter is not installed by default with name python, so that it does not conflict with other installed Python 2.x executable.



Previous                                                 Next                                                 Home

No comments:

Post a Comment