Python from Scratch: Getting Started
videos

Python from Scratch: Getting Started

Tutorial Details
  • Program: Python
  • Difficulty: Easy
  • Estimated Completion Time: 20 minutes
This entry is part 1 of 5 in the Python from Scratch Session
Next »

Welcome to Python from Scratch, where I’m going to teach you the ins and outs of Python development… from scratch.

In this first lesson, we’re going to choose a version, install Python, and then create the obligatory “Hello world” script. If you’re already familiar with Python, feel free to skip ahead to a later lesson in the series.


Video Tutorial

Subscribe to our YouTube and Blip.tv channels to watch more screencasts.

Companion Article


Choosing a Version

“It’s important to choose the right version.”

There are two versions of Python that are currently being developed: 2.x and 3.x. It’s important to make the right choice ,because there are several differences between the two. Once you’ve learned one, it can be a bit annoying to have to transition to the other. In this series, we’ll be working through version 2.7.1. You may want to go this route in order to follow along with the videos and articles in this series. That said, most things should work with either version. Version two has much more support from third party libraries, whereas version three has more features, and plenty of bug fixes and refinements.

To make things easier, a lot of features that are being added to version three have also being added to version two, so there’s less need to worry about the differences.


Installing the Interpreter

Once you’ve chosen a version, it’s time to install. Download the version of Python for your OS, and run the installer which will get it set up on your machine. There are three ways you can now use Python:

  • Python Shell- lets you run commands line by line.
  • IDLE GUI – lets you write more complex scripts, and run them in one go.
  • Text Editor – any text editor that runs on you system. You can then save it with a .py extension, and run it from the shell.

For now, launch the shell to test if it works correctly. On Windows, navigate to the directory you installed Python. By default, it should be C:\Python27 Once there, launch python.exe. If you’re on Mac or Linux, launch the Terminal, then type python.

I personally find IDLE to be unpleasant to use; so for most of this series, we’re going to be using a standard code editor. If you would rather use an IDE, there are plenty of good ones:


Hello World!

No we’re all set up; let’s write your first bit of Python! Go to the shell, type print "Hello World!", and hit enter. The phrase Hello World! should appear.

And that’s it: it really is as simple as that. You’ve written your first Python program! Now is a good opportunity to highlight one of the differences beween version two and three: they changed print from a statement to a function. Don’t worry too much about what those words mean for now. All you need to know is that, if you chose to use version three, you need to write print("Hello World!") — the only difference is that you don’t use brackets. We’ll learn about the technical reasons behind this in a future lesson.


Conclusion

So in this lesson, we set ourselves up with a fresh Python installation, discussed the best tools to write code, and wrote our first program. If you have any questions, I’m happy to answer them in the comments, and I hope you’ll join me for the rest of this series.

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.rickgrossman-blog.com R. Grossman

    A nice effort but not perfect.

  • http://mayavps.com Omar

    Very helpful for getting started. Thanks!

  • Luiz K.

    dude, srsly? this?
    i’m not retarded! i little ‘googling’ would’ve been more useful!

  • Rashid Omar

    Pyscripter rules! and version 3 should be encouraged as Guido mentioned recently.

  • http://relumastudio.com reluma

    great tut! thanks giles and nettuts! can’t wait to watch more of this series!

  • Ahmad Musaffa

    I think &lta href=”http://www.aptana.com”&gtAptana&lt/a&gt is a good ide for those who want to work on python framework. It is based on Eclipse.

  • Ahmad Musaffa

    I think Aptana is a good ide for those who want to work on python framework. It is based on Eclipse. Can be found on http://www.aptana.com.

  • http://www.marcomonteiro.net Marco Monteiro

    Love it. I’ll be doing all the tutorials for sure. =)

  • Michael

    Hmm… I haven’t watched the video, but the article is quite poor.
    This is meant to be a ‘from scratch’ tutorial, but you’ve missed out two key point for those new to Python… — – What is Python?
    - What can I do with it?

  • Adam Paterson

    Even if I take nothing else from this tutorial, learning that TAB autocompletes functions and filenames in terminal has made my night complete!

  • Ignasio

    I see you like minecraft

  • http://blog.xenodesystems.com/ Manuel Escudero

    Do you Know about Ninja-IDE? Currently is THE BEST cross platform Python Specific IDE out there, more info about it at:

    http://www.ninja-ide.org/

    Cheers :)

    P.S. Your Lessons are AWESOME!

  • rino19ny

    great tutorial!

    i agree that IDEs are a hassle and more trouble than help. i prefer using vi. :-P

  • Gemini

    The series does say “Python from Scratch” so rather than come here to crap out dung, just stay quiet or do us all a favour and take a dive from a bridge.

  • Chris G

    So many critics yet none have ever bothered to take the time to teach others. Just leech off of other peoples generosity and then criticize them for it. How disgusting. Anyway… thanks for sharing this tut!

  • Medhat

    Nice Tutorials It’s Too useful

  • http://www.factopedia.blogspot.in Factopedia

    i found the tutorial indeed useful for me but i want to know about running python in notepad++ and thats what i am missing .i am a beginner in python and will begin with python 2.7 let me know how to code in notepad++ and simple file system for python in unix

  • Pablo

    Thanx men I think that a tutorial from scratch should starts from the very begining like this one.

  • Daniel M.

    Excellent tutorial, easy to understand and well-paced, you have a pleasant speaking voice unlike some other tutorials I’ve watched. Thanks Giles

  • Sarah

    I’m actually very new to programming in general so forgive me if my questions seem very basic. I’m having trouble running files from specific locations. A little googling has allowed me to learn how to determine the absolute path so I ended up saving my py file in the folder that python is set to access. I was able to run the py file but when I went to run the same file again, the terminal wouldn’t produce any output. No error messages, it just did nothing. I want to be able to access files in different folders. I also want to know why the terminal refuses to run the same code twice? I saw that you were able to do that in your tutorial. Not sure what else to google. Hope you can help! The video was very helpful, thank you!

    I’m using Windows, python 2.7.3 64 bit, notepad++ as my text editor, and I’m not sure what else you need.

  • Patrick

    Actually having some issues getting the Terminal to locate the .py file that I had made. Running on windows 7 and simply trying “cd documents” did nothing, so after a long while of trying to figure out how to navigate files in python shell without getting “file “”, line one. SytaxError: invalid syntax” I got nothing. Anyone think they could help out?

  • David Ashby

    Say you wrote a small basic application in Python, then wanted to send it to someone who had not got Python installed, what would you need to do to enable the end user to be able to use it on their PC. Is distributing a Python application easier for a specific end user i.e. Apple, Windows etc?

    • boobula

      Try cx_freeze