An Introduction to Python For Undergraduate Engineers/Getting Started

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Python can be run in two modes, the first is called interactive mode. This is where every command you type in is immediately interpreted by python and the result outputted onto your screen. For example type:

print("Hello and welcome to python!!!")

This will immediately print 'Hello and welcome to python!' on your screen.

Alternatively you can use python in non-interactive (standard) mode. Write your lines of code into a file, save it and then run that file. This is convenient if your program starts to become large - otherwise you would have to type all the lines of your program every time you started using python.

When you first load IDLE, it is running in interactive mode. To write a program script (to save and run later), click on 'File; New Window'. Here you can write your program and save it. To run it you can either click on 'Run; Run Module' or press F5. Alternatively, you can run a python script by typing the following in a DOS Prompt (or in the Terminal on a Linux machine).