Home arrow Python arrow Page 2 - Introduction to Python Programming

No one expects the Spanish Inquisition! - Python

Python has very little to do with Eric Idle or John Cleese. It's an interpreted, object-oriented scripting language. Designed for clarity and simplicity, it's useful for creating large programs and for gluing pieces of other programs together. Keep reading to add Python to your personal programmer's toolkit.

  1. Introduction to Python Programming
  2. No one expects the Spanish Inquisition!
  3. Working with Numbers
  4. Python Mathematical Operators
By: James Payne
Rating: starstarstarstarstar / 10
November 12, 2007

print this article



As is the case with all computer programming tutorials, the first thing you learn to do is print some text to the screen. Normally it is a stupid “Hello World” program, but you are far too cool for that. Besides, the Spanish Inquisition is seeking us out, and the last thing we want to do is send a big old greeting out to the world. Here is how you print text to a monitor:

#!/usr/local/bin/python #this line must be included in every program

print “We are the Spanish Inquisition!”

The above code will print this to your monitor:

  We are the Spanish Inquisition!

To view the program in Python, save the file as firstprogram.py and open it in Python (type python firstprogram.py). Note that you must make sure that you can view and edit file extensions in your operating system, otherwise Notepad will change your file to a .txt and it will not work. To remedy this, simply turn on view file extensions, and rename the file with a .py extension.

You will note several things about the preceding code. First, the first line: #!/usr/local/bin/python tells the computer where Python is located. If you change where your python directory is located, you will have to change it in your code as well. This line must appear in all of your Python code.

Next, the line print “We are the Spanish Inquisition!” tells the computer to literally print the sentence in quotations to the user's monitor. Pretty simple right?

If we wanted to print more than one line of code we could do this:

#!/usr/local/bin/python #this line must be included in every program

print “We are the Spanish Inquisition!”

print “We have two weapons!”

print “One...fear!”

print “Two...obfuscation!”

print “And vigilance!”

print “Oh shucks did I say two weapons? I meant three.”

print “Why don't I step outside, then we will re-enter and begin again.”

This would result in the printout:

  We are the Spanish Inquisition!

  We have two weapons!



  And vigilance!

  Oh shucks did I say two weapons? I meant three.

  Why don't I step outside, then we will re-enter and begin again.

A Brief Word On Terminology

In the above code sample we worked with the print command. This was followed by quotation marks and some text, which is referred to as an argument. The text in the argument is referred to as a string. The combination of the command and the argument is known as a statement. So the line: print “We are the Spanish Inquisition!” is an example of a statement.

>>> More Python Articles          >>> More By James Payne

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates


Dev Shed Tutorial Topics: