0% found this document useful (0 votes)
90 views

LECT 6 Python

The document discusses two modes for interacting with Python: interactive mode and script mode. In interactive mode, Python waits for commands to be entered one by one. The Python shell allows testing code snippets immediately by prompting for input and printing output. Help and documentation can also be accessed from the interactive shell. Script mode runs a Python program from a source file without prompting for input between lines of code.

Uploaded by

martiin
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

LECT 6 Python

The document discusses two modes for interacting with Python: interactive mode and script mode. In interactive mode, Python waits for commands to be entered one by one. The Python shell allows testing code snippets immediately by prompting for input and printing output. Help and documentation can also be accessed from the interactive shell. Script mode runs a Python program from a source file without prompting for input between lines of code.

Uploaded by

martiin
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Two Ways Of Interacting

With Python

• We can use Python in two modes:

• Interactive Mode

• Script Mode

1. In Interactive Mode, Python waits for us to enter command.

2. In Script mode, Python interpreter runs a program from the


source file.
1. The Interactive Mode

• Python interpreter in
interactive mode is commonly
known as Python Shell.

• To start the Python Shell enter


the following command in the
command prompt:
• python

• Doing this will activate the Python


Shell and now we can use it for
running python statements or
commands
The Interactive Mode

• What we have seen on the previous slide is called Python


Shell. 

• >>> is known as python prompt or prompt string,


and it simply means that Python Shell is ready to accept
our commands.

• Python Shell allows us to type Python code and see the


result immediately.
The Interactive Mode

• In technical jargon this is also known as REPL which


stands for Read-Eval-Print-Loop.

• Whenever we hear REPL we should think of an


environment which allows us to quickly test code snippets
and see results immediately, just like a Calculator.

• Some examples of commands / code snippets to be run on


shell are shown in the next slide
The Interactive Mode
The Interactive Mode

• Not only mathematical calculations , we also can run


some basic python commands on Python Shell

• For example: Type the following command:

• print(“Hello Bhopal”)

• And you will get the text displayed on the Shell


The Interactive Mode

• We must remember that Python is also a case sensitive


language like C or C++ .

• So the function names must appear in lower case ,


otherwise Python generates Syntax Error , as shown
below
Getting Help From Shell

• We can also use help on Shell for getting information


on Python topics.

• To do this we need to type help( ) on the prompt string


on the Shell
Getting Help From Shell

• Now we get help on various Python topics .

• For example to get a list of all the available keywords in


Python , we can write the command “keywords”
Quitting Help

• To come out of help mode , we just have to strike


ENTER key on the prompt
Quitting Shell

• To come out of Python Shell , we have to type the


command exit( ) or quit( ) on the prompt string

You might also like