How To Start Python on Bucknell's Linux Computers
Notes originally by Professor Hyde
- Log on to one of the Linux machines in room 164 Breakiron or 213 Dana.
- To open a “Terminal” window, select Applications ->Accessories->Terminal from top menu, or with right mouse button in background, select Open in Terminal.
- To logoff of Linux machine, select from top menu System->Log Out account_name.
- To run the Python interpreter by itself in interactive mode, type in a terminal window at the prompt:
pythonType one line of Python at the
>>>
interactive prompt to try out a snippet of code.Type
quit()
orControl-d
to quit python.
- To use Python's simple integrated development environment, type in a terminal window at the prompt:
idle3which opens a new window with interactive prompt>>>
. Try>>> 6*7To enter a Python program within Idle, select File->New Window to open an editor window. Then type:
# Simple Python program def big_number(n): return 2**n x = int(input('Enter integer value: ')) y = big_number(x) print('2 to the power of', x, 'is', y)Save your file with
.py
extension.To run your program, select Run->Run Module in the editor window. Try 100 for input.
- Use
dir(module_name)
to see a listing of all the functions in a module. Try the following at the Idle interactive prompt. In using thedir
orhelp
function, you can always type the letter 'q' to stop the displaying more information.
import random # import the module random dir(random)- Use
help(module_name)
to see the manual page on a module. Try
help(random)- Use code>help(module_name.function_name) to see short description of the function. Try
help(random.choice)- You may use
dir()
andhelp()
on a variable that has been assigned a value. Try
s2 = 'Bison' dir(s2) help(s2.lower)