The Python Command Line (CLI)

From Training Material
Jump to navigation Jump to search


Overview

  • You can use any Python command from the interactive Python command line:
>>> print 4**2
16
>>> a = 'blue'
>>> print a
blue
>>>
  • Everything works in exactly the same way as it would in a program.
  • You can define code blocks by writing extra lines:
>>> for i in range(3):

print i

0
1
2
>>>

Tips

  • You can leave the command line by Ctrl-Z (Windows) or Ctrl-D (Linux).
  • The CLI works great as a pocket calculator.
  • Writing code blocks with 2+ lines in the CLI gets painful quickly.
  • From IDLE, you can execute a program in the command line by pressing F5.

More Info

An enhanced CLI with syntax highlighting and tab expansion is provided by the Ipython package (Windows/Linux/Mac) – http://ipython.scipy.org.