Python Interpreter and Interactive Mode TRB CSI › Python Programming › Python interpreter and interactive mode

Python Interpreter and Interactive Mode

Python Interpreter Python Interpreter என்பது நாம் எழுதும் Python source code-ஐ read செய்து, process செய்து, execute செய்ய உதவும் software. Simple-a சொன்னால்: Python code-க்கும் computer-க்கும் நடுவில் வேலை செய்யும் execution system தான் Py…

Free Beginner 15 min 92 cards 19 programs 10 MCQs v2
Definition
Meaning

Python Interpreter

Python Interpreter என்பது நாம் எழுதும் Python source code-ஐ read செய்து, process செய்து, execute செய்ய உதவும் software.

Python code-க்கும் computer-க்கும் நடுவில் வேலை செய்யும் execution system தான் Python Interpreter.

Interactive Mode

Interactive Mode என்பது Python commands-ஐ one by one type செய்து Enter press செய்தவுடன் immediate result பெறும் mode.

Simple Explanation
Core idea

என்று எழுதுகிறோம்.

நாம் Python-ல்

print("Hello")

Detail 02

Computer நேரடியாக Python syntax-ஐ புரிந்து கொள்ளாது.

அதனால்
  1. Python Code
  2. Python Interpreter
  3. Code Process ஆகும்
  4. Execute ஆகும்
  5. Output கிடைக்கும்
Program
Example
Python 1 lines
1print("Hello")
Verified output
Hello
Learning Run Mode — this is the output the author verified, not a live execution.
Output
Hello
Context

இதில் Python Interpreter தான் print() என்ன செய்ய வேண்டும் என்று புரிந்து execute செய்கிறது.

Interactive Mode Simple Explanation

என்று வரும்.

Python இப்போது command வாங்க ready-ஆக இருக்கிறது

என்று அர்த்தம்.

Program
Example
Python 1 lines
1>>> 10 + 20
Explanation
Core idea

30

இங்கு

10 + 20 type செய்கிறோம்.

Detail 02

Enter press செய்கிறோம்.

உடனே

30

Detail 04

வருகிறது.

Detail 05

இதுதான் Interactive Mode.

Flow
Python Interpreter Flow
  1. Python Source Code
  2. Interpreter receives the code
  3. Syntax checked
  4. Internal processing / bytecode generation
  5. Python Virtual Machine executes
  6. Result / Output
Simple Exam Flow
  1. Programmer writes Python code
  2. Python Interpreter
  3. Execution
  4. Output
Interactive Mode Flow
  1. Python Shell Open
  2. User types a command
  3. Press Enter
  4. Interpreter executes it
  5. Immediate Output
  6. Next >>> prompt appears
Program
Example
Python 1 lines
1>>> 5 + 5
Explanation
Core idea

10

Detail 01

Last >>> என்ன சொல்கிறது?

Detail 02

Next command type செய்ய Python ready.

Detail 03

Interactive Mode-க்கு separate programming syntax கிடையாது.

Detail 04

Python Shell-ல் normal Python statement type செய்ய வேண்டும்.

Syntax
General form
Python 1 lines
1>>> expression
Program
Example
Python 1 lines
1>>> 5 + 3
Explanation
Core idea

8

Detail 01

Variable:

Program
Python 2 lines
1>>> x = 10
2>>> x
Explanation
Core idea

10

Detail 01

Print statement:

Program
Python 1 lines
1>>> print("Python")
Explanation
Core idea

Python

Detail 01

Simple Addition

Program
Python 1 lines
1>>> 10 + 20
Explanation
Core idea

30

Detail 01

Using Variables

Program
Python 3 lines
1>>> x = 10
2>>> y = 20
3>>> print(x + y)
Explanation
Core idea

30

Detail 01

Multiplication

Program
Python 3 lines
1>>> a = 5
2>>> b = 4
3>>> a * b
Explanation
Core idea

20

Detail 01

String

Program
Python 2 lines
1>>> name = "Python"
2>>> print(name)
Explanation
Core idea

Python

Detail 01

Comparison

Program
Python 1 lines
1>>> 10 > 5
Explanation
Core idea

True

Detail 01

Division

Program
Python 1 lines
1>>> 10 / 2
Explanation
Core idea

5.0

Important
  1. Python / operator normally floating-point result கொடுக்கும்.

  2. So

    >>> 6 / 2

  3. 3.0

Explanation
Program 7
Core idea

Direct Expression

Detail 01

Interactive Mode-ல் print() இல்லாமலேயே expression result பார்க்கலாம்.

Program
Python 1 lines
1>>> 100 + 200
Explanation
Core idea

300

ஆனால் Script Mode-ல்

100 + 200

Detail 02

என்று மட்டும் எழுதி run செய்தால் normally screen output கிடைக்காது.

Detail 03

அங்கு:

Program
Python 1 lines
1print(100 + 200)
Explanation
Core idea

என்று எழுத வேண்டும்.

Detail 01

இது முக்கியமான difference.

Program
Example
Python 3 lines
1>>> x = 10
2>>> y = 20
3>>> print(x + y)
Verified output
30
Learning Run Mode — this is the output the author verified, not a live execution.
Output
30
Program
Another example
Python 1 lines
1>>> 5 * 4
Verified output
20
Learning Run Mode — this is the output the author verified, not a live execution.
Output
20
Program
Another
Python 1 lines
1>>> "Hello" + " Python"
Verified output
'Hello Python'
Learning Run Mode — this is the output the author verified, not a live execution.
Output
'Hello Python'
Line by Line
1
x = 10
x என்ற variable create ஆகிறது. அதில் value: 10 store செய்யப்படுகிறது. இங்கு: x → Variable name = → Assignment operator 10 → Value
2
y = 20
y என்ற variable-க்கு 20 assign செய்யப்படுகிறது. Current values: x = 10 y = 20
3
print(x + y)
முதலில் Python: x + y calculate செய்கிறது. அதாவது: 10 + 20 Result: 30 பிறகு print(): 30 screen-ல் display செய்கிறது.
Dry Run
Execution traceRead top to bottom · highlighted cells show the current value4 states
StepStatementxyOutput
01Iteration 1x = 1010--
02Iteration 2y = 201020-
03Iteration 3x + y evaluated102030
04Iteration 4print() displays result102030
Dry Run
Execution traceEvaluate the expression from left to right
TraceInteractive Mode Dry Run
Input
>>> 5 * 4
Dry Run
Execution traceRead top to bottom · highlighted cells show the current value5 states
StepProcessResult
01Iteration 1User enters 5 * 4Expression received
02Iteration 2Interpreter identifies *Multiplication
03Iteration 35 × 4 calculated20
04Iteration 4Result displayed20
05Iteration 5>>> appears againReady for next command
Comparison
Interactive Mode vs Script Mode
PointInteractive ModeScript Mode
Working styleOne command at a timeComplete program
Prompt>>>Normally no >>>
OutputImmediateAfter program execution
File requiredNoUsually Yes
File extensionNot required.py
Suitable forSmall testingLarge programs
LearningVery usefulAlso useful
Code savingNormally temporary sessionSaved permanently
DebuggingQuick testing easyBetter for full programs
ProjectsNot idealRecommended
Comparison
Interpreter vs Compiler
PointInterpreterCompiler
General ideaExecutes program through runtime processingTranslates program before/for execution
Error testingOften encountered during executionOften many compile-time errors reported during compilation
DevelopmentQuick experimentationBuild/compile step common
PythonCommonly called interpreted-
C/C++-Commonly called compiled languages
Important
  1. Python பற்றி technically deep-a கேட்டால்
    Python source codebytecodePython Virtual Machine execution
  2. என்று சொல்லலாம்.

  3. ஆனால் basic competitive exam answer

    Python is an interpreted language.

Important
  1. Python Interpreter executes Python code, while Interactive Mode allows the user to enter Python statements one by one and get immediate results.

  2. இதை கண்டிப்பாக நினைவில் வைக்க வேண்டும்.

  3. Very Important Prompts

  4. Primary Prompt

  5. Python next instruction வாங்க ready என்பதை குறிக்கும்.

  6. Secondary / Continuation Prompt

  7. ...

  8. Multi-line statement இன்னும் complete ஆகவில்லை என்பதை காட்டும்.

Program
Example
Python 2 lines
1>>> if 10 > 5:
2...     print("Yes")
Verified output
15
Learning Run Mode — this is the output the author verified, not a live execution.
Explanation
Core idea

...
Yes

Common Mistake
Error 1
Context

>>>-ஐ Python program file-ல் எழுதுவது

>>> x = 10
>>> print(x)

இந்த >>> என்பது Python code இல்லை.

இது Interactive Shell prompt.

x = 10
print(x)
Common Mistake
Error 2
Context

Interactive result மற்றும் print() ஒன்றே என்று நினைப்பது

30

print() இல்லாமலே result தெரியும்.

என்று மட்டும் இருந்தால் visible output வராமல் இருக்கலாம்.

print(10 + 20)

Common Mistake
Error 3

Python Interpreter ஒரு compiler அல்ல என்று absolute-a சொல்வது

Basic exam-ல் Python interpreted language.

ஆனால் Python implementation internally bytecode compilation செய்யலாம்.

Correct understanding:

Python is generally classified as an interpreted language, although CPython internally compiles source code to bytecode before execution by the Python Virtual Machine.

Common Mistake
Error 4
Context

... Error symbol என்று நினைப்பது

...

means error.

... என்பது generally continuation prompt.

Memory Trick

>>> = Give me the next command

  1. "Next command என்ன?"Interpreter Memory TrickI = Interpreter = Instruction ExecutorInterpreter → Instruction-ஐ execute செய்ய உதவும்.Interactive Memory TrickInteractive = Immediate InteractionType
  2. Enter
  3. Immediate Result.py Memory TrickPY = Python

.py

TRB Point
TRB Point 1

Python is commonly classified as an interpreted high-level programming language.

TRB Point
TRB Point 2

Python Interactive Mode-ன் primary prompt:

TRB Point
TRB Point 3

Continuation / Secondary prompt:

...

TRB Point
TRB Point 4

Python source file extension:

.py

TRB Point
TRB Point 5

Interactive Mode is mainly used for:

quick testing, calculations, experimentation and learning.

TRB Point
TRB Point 6

Script Mode is mainly used for:

saving and executing complete Python programs.

TRB Point
TRB Point 7
  1. Common Python execution concept

    Source Code

  2. Bytecode

  3. Python Virtual Machine

  4. Execution

TRB Point
TRB Point 8

Interactive Mode generally executes:

one command or statement at a time.

Interview Point
Question 1

What is a Python Interpreter?

Answer

A Python Interpreter is the software/runtime system that processes and executes Python code. In common implementations such as CPython, the source code is compiled into bytecode and then executed by the Python Virtual Machine.

Interview Point
Question 2

What is Interactive Mode in Python?

Answer

Interactive Mode allows us to enter Python commands one at a time and get immediate results. It commonly displays the >>> primary prompt.

Interview Point
Question 3

What is the difference between Interactive Mode and Script Mode?

Answer

Interactive Mode is mainly used for quick testing and immediate results. Script Mode stores Python code in a .py file and is better for larger and reusable programs.

Interview Point
Question 4

What does >>> mean in Python?

Answer

>>> is the primary prompt of the Python interactive shell. It indicates that Python is ready to accept the next command.

Interview Point
Question 5

What does ... represent?

Answer

... is commonly called the secondary or continuation prompt. It appears when Python expects additional lines to complete a multi-line statement.

MCQ
71Python is commonly classified as a:
Choose one answer
MCQ
72Which is the primary prompt in Python Interactive Mode?
Choose one answer
MCQ
73Which prompt is generally used for continuation?
Choose one answer
MCQ
74What is the extension of a Python source file?
Choose one answer
MCQ
75Which mode is most suitable for quick testing?
Choose one answer
MCQ
76What is the output? >>> 5 * 4
Choose one answer
MCQ
77What is the output? >>> 10 / 2
Choose one answer
MCQ
78Which is more suitable for a large application?
Choose one answer
MCQ
79Consider: >>> x = 10 >>> x What is displayed?
Choose one answer
MCQ
80Which of the following is NOT part of Python code?
Choose one answer
Practice
Practice 1

Interactive Mode-ல்:

5 + 10

run செய்து output கண்டுபிடிக்கவும்.

Output
Expected Output
15
Practice
Practice 2

Two variables create செய்யுங்கள்:

x = 25
y = 15

இரண்டையும் add செய்து result பார்க்கவும்.

Practice
Practice 3

கீழே உள்ள code output கண்டுபிடிக்கவும்:

>>> a = 5
>>> b = 6
>>> a * b

Answer:

30

Practice
Practice 4

Interactive Mode-ல் உங்கள் பெயரை store செய்து print செய்யுங்கள்.

Program
Example
Python 2 lines
1name = "Nagarajan"
2print(name)
Practice
Practice 5

இந்த expressions-ஐ execute செய்யுங்கள்:

20 + 30
50 - 10
5 * 8
100 / 4

Practice
Practice 6

இந்த statement output என்ன?

>>> 25 > 10

Answer:

True

Practice
Practice 7

Python Interactive Mode மற்றும் Script Mode-க்கு 5 differences எழுதுங்கள்.

Practice
Practice 8

Fill in the blanks:

Python Interactive prompt is .
Python continuation prompt is
.
Python file extension is .
Python is commonly a/an
language.
Large Python programs are usually stored in ____ mode.

Answers:

...
.py
interpreted
Script

Summary
  1. Python Interpreter Python code-ஐprocess செய்து execute செய்ய உதவுகிறது.
  2. Pythonis commonly called an interpreted language.
  3. Interactive Modecommand-by-command executionக்கு பயன்படுகிறது.
  4. Interactive Mode immediate resultகொடுக்கிறது.
  5. >>> என்பது Python Primary Prompt.
  6. ... என்பது Secondary /Continuation Prompt.
  7. Python source file extension .py.
  8. Interactive Mode quick testingக்குuseful.
  9. Script Mode large and reusableprogramsக்கு suitable.
  10. CPython internally source code-ஐbytecode-ஆக compile செய்து Python Virtual Machine மூலம் execute செய்கிறது.
Quick Revision
  1. Interpreter → Python code executeசெய்ய உதவும்.
  2. Interactive Mode → Type → Enter →Immediate Result.
  3. >>> → Primary Prompt.
  4. ... → Continuation Prompt.
  5. .py → Python source fileextension.
  6. Interactive Mode → Small testing.
  7. Script Mode → Large programs.
  8. Python → Commonly classified asinterpreted.
  9. PVM → Python Virtual Machine.
Text size
17px
Theme
Contents
Print / PDF
Program