Python interactive and script mode
Introduction
We all know that the fundamental for every computational framework is programming. Every programming concept starts with its basics. So we have started articles based on basics of python programming language. Python is a high level language mainly used in web development and data science. For beginners writing programs in python is quite easy. Python have two different modes to run programs. They are
- Interactive mode
- Scrip mode
For beginners who want to learn python interactive mode is good for them. As it is named it is a quick way of running block of code or small programs. It gives quick responses for every line of code. Interactive mode operates through python shell which comes with python installation. It is a good option if you want quick response of your code or just started with python.
To access the interactive mode open the terminal of your operating system and type python. Make sure python is installed on your computer. Then it will show default python interface. >>> Sign shows that the shell is ready to execute the code. Then type the block of code that you want to execute. After a single line of code, it will send the code to the python interpreter to execute the code and give you quick response.
>>> a=int(input("enter a number:"))
enter a number:
It is also possible to run multiple codes. You can even copy the code from some where else and paste here to execute.
>>> a=int(input("enter a number:"))
enter a number:45
>>>if a>=50:
... print(a"is greater than or equal to 50")
...else:
... print(a"is smaller than 50")
45 is smaller than 50
Interactive mode comes with help() command if you have some doubt regarding anything. Simply hit help() in the shell and the the help screen will open.
To get help about any command just type the command i.e input() and it will show information about the command. To exit the help panel type 'q'.
Pros and cons
- It is good to run small blocks of codes
- Easy for beginners
- Faster as it execute every line of code and gives intermediate results
- Learning python is good with interactive mode
- Not suitable for long scripts of codes
- GUI programs can't be run with interactive mode
- Not suitable for professionals
- Editing the code is difficult
Script mode
Script mode is a good option for writing long codes. As it is mentioned above interactive mode is not suitable to run longs scripts of codes. Here the role of script mode comes to play. You can write all the whole program and save it and run the whole program at once in script mode. Script mode can be accessed through any of the text editor or IDE. 'IDLE' is the default ide that comes with python to run codes. To run a program in script mode, write the code and save it in any folder with '.py' extention. Py stands for python. After saving the program is ready to run. In IDLE after writing the code press CLTR+S to save the program then press F5 to run it.
Pros and cons
- Its easy to run large blocks of codes
- Editing the code is easier than interactive mode
- Easy for beginners as well as for experts
- Not suitable to run small blocks of codes
- Everytime you have to save the program in order to run it
IDE (integrated development environment)
As a beginner or an expert, its becomes quite difficult to find out all the errors and edit the code after writing the whole program. Here comes to play the role of IDE. An IDE enables the programer to handle the code with an ease by providing various programming facilities. With an IDE its its easy to write programs. It increases the productivity of the programer. Syntax highlighting, auto-completion, auto-saving, quick responses, debugging are some major features of an IDE.
Syntax highlighting is a very important feature provided by an IDE. Sometimes it becomes difficult to understand the program for beginners due to hard syntaxes. Syntax highlighter highlights different syntaxes of a program which helps the understand that program well.
>>>a=int(input("enter a number:"))
>>>#here a is input
>>>print(a)
Here black colour is identifier, blue is keyword, green is string, red is comment and purple is function.
This is how a IDE highlights different syntaxes in python.
One major features that is always needed by a programer is debugger. And this is the feature for which you need to have a IDE because a debugger can be only found in an IDE or in debugging softwares. The function of a debugger is to find the bugs in the program and then fix it.
Some IDE comes with both interactive mode and script mode for better experience of user.
Some famous IDEs for python are IDLE, pycharm, atom, sypder, pydev etc.
Comments