Non-Programmer's Tutorial for Python 2.6/Induction

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

Simple Programs[edit| edit source]

Python is such a simple language even a non-programmer could understand it. Here are some examples:

 print "Hello, World!"

This program prints "Hello, World!" on the screen. Even longer programs can be easily understood

  # Stuff after number signs are comments that have no functionality
  # They are useful for explaining how things work though.
 name = raw_input("What is your name?")  # Asks the person using the program what their name is
  if name == "John":                     # If the person types John and presses enter
       print "Hello, John! How are you?" # The program prints Hello, John! How are you?
  elif name == "Teddy":                  # If the person types Teddy and presses enter
       print "Go away!"                  # The Program prints Go Away!
  else:                                  # If the person types any thing else and the presses enter
       print "Good day," , name          # The Program prints Good day followed by what the person typed

Weird Features[edit| edit source]

Some weird features of Python include the fact that grouping is shown by how indented a line is. For example,

 if value == input:
    do this

is not the same as:

 if value == input:
  do this

Instead, some languages prefer to have everything written like this:

 {if value
     == input[d

In other languages, you can organize it in any way you want. It's different in Python.