Home > Articles > Open Source > Python

Five Minute Python Programming Primer

  • Print
  • + Share This
This user-friendly Python tutorial will have you up and running in Python programming in no time. A perfect primer for beginners, you will program a simple game after learning about variables, programming math, logic, for loops and if statements, and more.
Like this article? We recommend

Are you curious about what programming is? Take a quick tour of Python, a powerful, easy-to-learn programming language!

So, what is programming anyway?

There’s been quite a bit of fuss in the past few years about programming. Online schools and classes have popped up, and it seems everyone is pushing everyone they can to learn a bit of code.

In short, programming is the art of telling a bit of hardware what to do. This hardware (the stuff you can hold in your hands) might be your computer, or it might be a chip in your car that helps manage oxygen intake. It might do something as simple as note what time it is, or it might be on a satellite, taking in information about the temperature of Earth’s oceans and atmosphere.

Programming goes by many names, and they’re used interchangeably (though some will argue about some of the nuanced meanings of each). All you have to know for now is that programming, developing, and coding are all involved in writing software that gets hardware to do what you want.

Do only programmers need to program?

Though opinions vary, the world is quickly coming to a point where everyone needs to know a bit about the logic behind the computers that surround us.

Even before I was a full-time programmer, I used code to make my life easier. I learned SQL so I could create reports for another division at our company. I learned PHP so I could keep track of items that had dropped in an online game I played. I learned Python so I could generate an automated email to a boss about what tickets had been touched that week.

In each of these positions (office admin, gamer, and business analyst), I didn’t need to code. It wasn’t a part of my job description, and it was certainly never expected of me. But knowing how made my life easier, especially because I hated doing reports by hand, and abhorred keeping track of who got what the last time our guild raided together.

What does programming look like?

Most people think programming must look arcane, like the flood of characters that stream down the screens on The Matrix. Honestly, though, most programming today isn’t that hard to parse. Consider the following bit of code:

secret_number = 7

guess = input("What is your guess?")

if secret_number == guess:
    print "That's right! You win!"
    print "Sorry, that isn't right."

The above is written in Python, a language that’s been around for 22 years, and extensively used today. Can you guess what the code is doing?

If you take the code line by line, you can probably figure it out. Here’s what each line is doing:

  •  We set the secret number to seven.
  •  We get a guess from the user.
  •  If the secret number is the same as the guess...
  • We print out a message that lets the user know that they guessed correctly.
  •  Otherwise...
  • We tell the user they weren’t right.

Basically, it’s a very simple number guessing game.

Can I program on my computer?

Absolutely! As long as you can install programs on your computer, you should be able to use it to program.

Though there are many languages out there, this article focuses on Python. It’s powerful, it’s easy to learn, and it’s easy to install.

If you have a Mac, then you should already have it installed! Bring up a terminal (search for ‘Terminal’ in Spotlight), then type ‘python.’ You should see something like this:

Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

This is the Python shell, and it’s where you play around with Python. Hit Command+D to exit it.

If you want a text editor with your shell, type ‘idle’ in your terminal window. A window will pop up that has a shell. Pressing Command+N will open a text window where you can write code to run later.

If you’re on a Windows machine, you can get the same thing as a Mac by downloading Python and installing it on your computer. IDLE (a program for editing and running Python) should show up in your installed programs once you’re done.

How much does this cost?

Python is free to all, both to download and to use. So, use it for fun, or make a million-dollar app with it; it’s the same cost for either.

  • + Share This
  • 🔖 Save To Your Account