Fandom

Python Wiki

Python Interactive Shell

43pages on
this wiki
Add New Page
Talk0 Share

General Information Edit

The Python Interactive Shell is an interactive interpreter that can execute Python commands without saving it to a file.

Starting it Edit

The Interactive Shell can be started with the bash-command
python
. If you want to run programs stored in a file on this shell, type in
python -i FILENAME.py
where FILENAME is the name of your file. This is useful for debugging.

Use it as a calculator Edit

As explained above, the Interactive Shell can execute Python commands. Same goes for simple calculations. Here are a few examples:

>>> 1 + 3
4
>>> 12 / 4
3
>>> 12 % 4
0

Logical expressions Edit

We can do the exact same thing with logical expressions, e.g.:

>>> True and (not False)
True
>>> (False or (not (False and True))) and True
True


File operations Edit

As we can open, write and read files by executing a script, we can also do that in this environment.

>>> f = open('test.txt', 'w')
>>> f.write('Hello ')
>>> f.write('World!')
>>> f.close()
>>> g = open('test.txt', 'r')
>>> for entry in g:
...     print(entry)
...
Hello World!
>>> g.close()
>>> import os
>>> os.remove('text.txt')

For further explanations about the usage of files, please look at Files.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.