Using Python’s Interactive Console to Run Programs

Intuitive Python — by David Muller (9 / 41)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Setting Up Your Environment and Using T his Book’s Companion Docker Image | TOC | Try Out Different Versions of Python with D ocker 👉

Python provides an interactive console where you can run Python code dynamically (without, for example, creating any source code files beforehand). Start Python’s interactive console by running python3 from your command line:

​ $ python3
​ Python 3.9.2 (default, Mar 12 2021, 18:54:15)
​ [GCC 8.3.0] on linux
​ Type "help", "copyright", "credits", or "license" for more information.
​ >>>

After you run python3, you’ll see several lines describing the version of Python you’re running. In the preceding example, Python is on version 3.9.2. As a reminder, the examples in this book all require Python 3.7 or higher.

After running python3, your cursor will be placed just after the >>> characters. This is where you can type and run Python code. (The >>> characters just serve as your prompt and are not syntactically or otherwise important in any way.) Let’s start by outputting the text hello world:

​ >>> ​print​(​"hello world"​)
​ hello world
​ >>>

Calling Python’s built-in print function outputs the “hello world” string to stdout, and indeed, you should see that text outputted on your machine in between two >>> entries.

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.