1. Python Basics1. Python Basics\1.1 Familiarizing Yourself with Python\1.1.1 Hello World!

1.1.1 Hello World!

 

We will start with a classic. Create a new Python file, type the following and run it (see the student guide for details):

 

  1. print "Jambo!"  

 

You should see this output:

 

Jambo!

 

Congratulations! You have just run a Python program. Jambo means hello in Swahili.

 

Let’s do another one. Create a new file, type the following and run it:

 

  1. print "All the things!"  
  2. print "print"  
  3. print "This sentence " + "has two halves."  

 

You should see this output:

 

All the things!

print

This sentence has two halves.

 

What are these programs doing? They are printing sentences. In Python and most other programming languages, print usually does not mean a paper printer. It means output something where the user can read it.

 

The first program has one line, and prints one thing. The second program has three lines, and prints three things in order.

 

Each of these lines is called an instruction (or a statement, or a command).

 

When you run these programs, what you are doing is telling Python to read each instruction, and execute it, in order.

 

 

DEFINITION: "Python" actually has two meanings:

 

First, Python is a language (like English, with a vocabulary and grammar rules) to write instructions for computers.

 

Second, the Python interpreter is a program that reads those instructions and executes them.

 

 

 

print is an instruction in the Python programming language. It prints text for users to read.  print usually outputs to a terminal.

 

 

DEFINITION: A terminal (also known as a console, or the command line interface) is a text-based program where users can input text, and other programs can output text. Many Python programs are run from a terminal, and the print command typically prints to the terminal by default.

 

                       

                                                     Figure 1: A sample terminal.

 

 

 

 

print can output to things other than terminals. Many web servers use print instructions to write web pages. A surprisingly large amount of the text you read online comes from print instructions.

 

 

Top of Page