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.

Add Comment

Discussion 88 Comments

Comment Page 2 of 2 1 2
  1. R. Grossman says:

    A nice effort but not perfect.

  2. Omar says:

    Very helpful for getting started. Thanks!

  3. Luiz K. says:

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

  4. Rashid Omar says:

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

  5. reluma says:

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

  6. Ahmad Musaffa says:

    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.

  7. Ahmad Musaffa says:

    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.

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

  9. Michael says:

    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?

  10. Adam Paterson says:

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

  11. Ignasio says:

    I see you like minecraft

  12. 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!

  13. rino19ny says:

    great tutorial!

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

  14. Gemini says:

    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.

  15. Chris G says:

    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!

  16. Medhat says:

    Nice Tutorials It’s Too useful

  17. Factopedia says:

    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

  18. Pablo says:

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

  19. Daniel M. says:

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

Comment Page 2 of 2 1 2

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.