Python Programming/Interactive mode - Wikibooks, open books for an open world (2024)


Python has two basic modes: script and interactive. The normal mode is the mode where the scripted and finished .py files are run in the Python interpreter. Interactive mode is a command line shell which gives immediate feedback for each statement, while running previously fed statements in active memory. As new lines are fed into the interpreter, the fed program is evaluated both in part and in whole.

Interactive mode is a good way to play around and try variations on syntax.

On macOS or linux, open a terminal and simply type "python". On Windows, bring up the command prompt and type "py", or start an interactive Python session by selecting "Python (command line)", "IDLE", or similar program from the task bar / app menu. IDLE is a GUI which includes both an interactive mode and options to edit and run files.

Python should print something like this:

$ pythonPython 3.0b3 (r30b3:66303, Sep 8 2008, 14:01:02) [MSC v.1500 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more information.>>>

(If Python doesn't run, make sure it is installed and your path is set correctly. See Getting Python.)

The >>> is Python's way of telling you that you are in interactive mode. In interactive mode what you type is immediately run. Try typing 1+1 in. Python will respond with 2. Interactive mode allows you to test out and see what Python will do. If you ever feel the need to play with new Python statements, go into interactive mode and try them out.

A sample interactive session:

>>> 55>>> print(5*7)35>>> "hello" * 2'hellohello'>>> "hello".__class__<type 'str'>

However, you need to be careful in the interactive environment to avoid confusion. For example, the following is a valid Python script:

if 1: print("True")print("Done")

If you try to enter this as written in the interactive environment, you might be surprised by the result:

>>> if 1:... print("True")... print("Done") File "<stdin>", line 3 print("Done") ^SyntaxError: invalid syntax

What the interpreter is saying is that the indentation of the second print was unexpected. You should have entered a blank line to end the first (i.e., "if") statement, before you started writing the next print statement. For example, you should have entered the statements as though they were written:

if 1: print("True") print("Done")

Which would have resulted in the following:

>>> if 1:... print("True")...True>>> print("Done")Done>>>

Interactive mode[edit | edit source]

Instead of Python exiting when the program is finished, you can use the -i flag to start an interactive session. This can be very useful for debugging and prototyping.

python -i hello.py

For i in range(-1,-5,-1):

 print(i)
Python Programming/Interactive mode - Wikibooks, open books for an open world (2024)
Top Articles
Walmart’s HRM: Training, Performance Management - Panmore Institute
Active Directory Organizational Unit (OU): Ultimate Guide – TheITBros
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Craigslist Free En Dallas Tx
Lexi Vonn
Greedfall Console Commands
Rabbits Foot Osrs
Exam With A Social Studies Section Crossword
Rondale Moore Or Gabe Davis
Celsius Energy Drink Wo Kaufen
Snowflake Activity Congruent Triangles Answers
Newgate Honda
Reddit Wisconsin Badgers Leaked
The fabulous trio of the Miller sisters
Harem In Another World F95
Missed Connections Inland Empire
Mychart Anmed Health Login
Walmart Car Department Phone Number
Quick Answer: When Is The Zellwood Corn Festival - BikeHike
Xxn Abbreviation List 2017 Pdf
Masterbuilt Gravity Fan Not Working
Maine Racer Swap And Sell
Xxn Abbreviation List 2023
Mchoul Funeral Home Of Fishkill Inc. Services
Google Flights To Orlando
5 Star Rated Nail Salons Near Me
Christmas Days Away
15 Downer Way, Crosswicks, NJ 08515 - MLS NJBL2072416 - Coldwell Banker
Everstart Jump Starter Manual Pdf
Beaver Saddle Ark
Metra Union Pacific West Schedule
Hannibal Mo Craigslist Pets
Frank 26 Forum
Keir Starmer looks to Italy on how to stop migrant boats
2023 Nickstory
Entry of the Globbots - 20th Century Electro​-​Synthesis, Avant Garde & Experimental Music 02;31,​07 - Volume II, by Various
Anderson Tribute Center Hood River
Umd Men's Basketball Duluth
QVC hosts Carolyn Gracie, Dan Hughes among 400 laid off by network's parent company
Content Page
Grizzly Expiration Date Chart 2023
Flappy Bird Cool Math Games
Zeeks Pizza Calories
Craigslist Sparta Nj
Theatervoorstellingen in Nieuwegein, het complete aanbod.
Shannon Sharpe Pointing Gif
Julies Freebies Instant Win
The Goshen News Obituary
De Donde Es El Area +63
Southwind Village, Southend Village, Southwood Village, Supervision Of Alcohol Sales In Church And Village Halls
Mazda 3 Depreciation
Selly Medaline
Latest Posts
Article information

Author: Dong Thiel

Last Updated:

Views: 5555

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Dong Thiel

Birthday: 2001-07-14

Address: 2865 Kasha Unions, West Corrinne, AK 05708-1071

Phone: +3512198379449

Job: Design Planner

Hobby: Graffiti, Foreign language learning, Gambling, Metalworking, Rowing, Sculling, Sewing

Introduction: My name is Dong Thiel, I am a brainy, happy, tasty, lively, splendid, talented, cooperative person who loves writing and wants to share my knowledge and understanding with you.