Python Interpreter : The Best Language Interpreter

Nov 29, 2016

2 mins read

Published in

Python is one of the best-interpreted languages and developed by Guido van Rossum in late 1980. Python is used as the first programming choice of Google, Ubuntu, RedHat and other IT product based companies.

The Python interpreter

The Python interpreter is a program which reads Python statements and executes them immediately. To use interpreter it requires opening the command prompt or terminal windows in your development environment and write command python, and it will show this result and start interpreter. I am using Window 10’s Ubuntu shell.

root@DESKTOP-H4BUM4V:~# python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

Python interpreter executes program statements immediately. To run python statements, Python command prompt will start in interactive mode and it will be very useful to try out things.

Here are some Examples of one-line commands:

root@DESKTOP-H4BUM4V:~# python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("Hello World")
Hello World
>>> 50 * 20
1000
>>> bin(5)
'0b101'
>>>

In above examples, one will print Hello World, other will do multiplication and the third one calculates Decimal to Binary using bin().

The »> prompt is used to enter one-line commands or code blocks that define classes or functions. Simple one-line commands are there in above example. In next example please find multi-line code blocks.

Here are some Examples of multi-line code block:

root@DESKTOP-H4BUM4V:~# python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> str1 = "Hello"
>>> str2 = "Hello"
>>> str1 == str2
True

In above example, it will compare two strings.

help() function is another awesome way to get help on python keywords, functions, etc.

Here is the example of checking syntax and guide of bin command. Press q to return to python interactive interpreter.

root@DESKTOP-H4BUM4V:~# python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help(bin)

Help on built-in function bin in module __builtin__:

bin(...)
    bin(number) -> string

    Return the binary representation of an integer or long integer.
(END)

I love the way Python Interactive Interpreter works. How about you?

Related Python Articles:

Read JSON File using Python Code and Prompt

JSON Pretty Print using Python- with Examples

Sharing is caring!