Python: Interactive Mode

Interactive mode is the quickest way you can start using Python. To use the Python interactive shell we just need Python installed on the machine.

Start Interactive Shell

Then just type the command “python“, and you will get into the interactive shell-

> python

Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>>
PowerShell

Or if you have Python 3 installed separately, and available as the command “python3“, like I have in my Ubuntu box, then type “python3” to access the interactive shell-

$ python3

Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>>
Bash

Interact with Interactive Shell

Then we can start interacting with the interactive shell-

>>> a = 100
>>> a
100

>>> b = 500
>>> b
500

>>> a + b
600

>>> a * b
50000

>>> print("Hello BigBoxCode")
Hello BigBoxCode

>>> print("a + b = ", a+b)
a + b =  600

>>> # some comment here
>>>
Bash

Evaluate Expression

We can use the Python interactive shell to evaluate expressions only-

>>> 2 + 4
6

>>> x = 3
>>> x + 8
11

>>> x
3

>>> "this is my sample string"
'this is my sample string'

>>> my_str = "abc" + " some extension"
>>> my_str
'abc some extension'

>>> 20 * 3 + 9 / (2 +3)
61.8
Bash

We can evaluate other Python expressions in the interactive shell-

>>> big_box_tpl = ("Big", "Box", "Code")

>>> big_box_tpl
('Big', 'Box', 'Code')

>>> type(big_box_tpl)
<class 'tuple'>


>>> "Big", "Box", "Code"
('Big', 'Box', 'Code')

>>> big_box_tpl = "Big", "Box", "Code"

>>> big_box_tpl
('Big', 'Box', 'Code')

>>> type(big_box_tpl)
<class 'tuple'>
Bash

Leave a Comment


The reCAPTCHA verification period has expired. Please reload the page.