Basics of Python Programming (JNNC Technologies)


Python is an interpreted programming language. Python source code are compiled to byte code as .pyc file, and this byte code can be interpreted.
There are two modes for using the Python interpreter:
  1. Interactive Mode
  2. Script Mode

Interactive Mode

Without passing python script file to interpreter, directly execute code to Python prompt.
Example:
>>>2+6
Output:
8
The chevron in the beginning of the 1st line, i.e. the symbol >>> is a prompt the python interpreter uses to indicate that it is ready. If the programmer types 2+6, the interpreter replies 8.

Script Mode

Alternatively, programmers can store Python script source code in a file with .py extension, and use the interpreter to execute the contents of the file. To execute the script by the interpreter, you have to tell the interpreter the name of the file. For example, if you have a script name MyFile.py and you’re working on Unix, to run the script you have to type:
python MyFile.py

Working with interactive mode is better when Python programmers deal with small pieces of code as you can type and execute them immediately, but when the code is more than 2-4 lines, using the script for coding can help to modify and use the code in future.

Post a Comment

0 Comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();