Tutorial Details
- Program: Python
- Difficulty: Easy
- Estimated Completion Time: 20 minutes
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
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:
- PyScripter (Windows)
- Eclipse with the PyDev plugin (Windows)
- Netbeans for Python (Windows, Mac, Linux, Solaris)
-
Visual Studio with
Python Tools (Windows) - Eric IDE, best on Linux, available in Ubuntu Software center
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.

The video cut off for me at 5 min, right in the middle of some sentence. The Hello World example doesn’t seem to be in it. However, still a nice series that I’ll definitely be following.
really really nice,
expecting the next one
I am so happy that Python is finally getting some love!
THANK YOU NETTUTS! I’VE WAITED SO LONG FOR THIS! MOAR PYTHON PLEASE!!!!
This is great.
I’ve written some production python code in the past and really dig it. Problem is that there’s not really very many good python screen-cast tutorials out there and I’m a visual learner (too impatient to delve into written docs for too long.) I was just thinking a few days back how nice it’d be to get some proper conventions knowledge and a new take from a seasoned python developer. …And here it is!
Thanks!
Nice new tread.. but i would like to se some JAVA WEB tutorials. Please begin with it!
Another good language to learn, thanks.
Agree with Andrea, would like to se some java web tutorials :)
Yahoo!! First Ruby, now Python! It’s been really fun to watch the growth here on Nettuts. Gotta hold onto this one for after graduation.
Love u tutsplus *~*
i’d looove to see some tricks of python running on GAE!!
Does this cut off at 5:00 for anyone else, as well?
yup
I’m glad to see Python tuts on net tuts. Good one guys.
Phenomenal tutorial. I look forward to delving deeper into web design with python. I’ve been working with it for a few years, but I haven’t really used it in that aspect.
Can’t wait for more!
Same here… It cuts off at 5.00
blip still not available in China please copy to S3 or youtube!
Awesome! Python is my favorite language, I would like to see how you can use it in web dev.
Yeah, Python!!! Thank you so much for focusing on this! Would love to see more on Django as well. You guys rock!!
Nice tut , but 2 much spaghetti on Nettuts in the recent months….2 many beginner level tuts recently…would be nice to see some advanced node.js tuts or some nice advanced oop php tuts
If your looking for something more advanced, you don’t have long to wait.. we’re doing one of these a week and the fourth episode is all about OOP in Python, so check back soon for something more challenging :)
Ahh…great then :) thx ..keep them coming :D
Why wait so long, we wan’t to learn python now! :D
Can’t wait for more tutorials on python, i’m doing a project with django and i need to learn some python asap before continuing. Too bad it’s only one video a week, but i’m still gonna follow it though! :)
Yeah! . watch up PHPes, someone trying to change your language and your religion with this Awesome language :)
When’s the next tutorial coming? It’s been way longer than a week!
Hell yeah! Finally a Python series.
Awesome, I’m really looking forward to this series! I’d love a nice intro to Python, then to take things future and explore Django.
Love the Hack Pro! =)
You can also use this IDE that was not mentioned. Which i personally use – there is a free and a paid version.
http://wingware.com/
eclipse is NOT restricted to windows, you can use it on mac and linux too
I personally love Aptana Studio : http://www.aptana.com/ – Web dev, Ruby and Python all in one.
Hey guys, please stop arguing over who has the best IDE. It’s newb stuff. Really… really… newb stuff.
Aptana is built on Eclipse.
so pumped on this! a friend of mine has been showing me some stuff to learn from for python! he has made some really impressive stuff using python, django, flask, hes one of those really gnarly guys that knows his stuff. a lot comes along with running django as well. that would be something great for some tut’s to come up about setting up the complete environment to run django apps on!
thanks for doing this series! im looking to step my game way up in the next 8 months! thanks net tuts!
Thanks for sharing this. Really liked the first part. I was think of starting the Python, and here I see the 1st part of the series. Waiting for the next part, best of luck.
Thanks.
This was great! I’m currently taking a Web Programming class as well as an Introduction to Programming, which is C++, and it’s interesting to see the similarities between programming languages, especially High-Level languages. I can’t wait for the next lesson.
Thanks Giles
Awesome! Net Tuts is becoming THE destination for all things web dev! Keep it up guys
Sweet now I can print stuff on the screen! Good thing there was this tut here for that, I would never have known how to do it.
I had never even considered looking at Python until seeing this tut. It may be fun so I’m glad you’re doing it. One suggestion? It’s not uncommon to forget the audio dynamics of a microphone a few inches from your mouth. By that I mean that not only spoken words are captured and amplified but swallowing, drinking, slurping etc. More than a little distracting and can be very annoying to listeners using headsets where the higher frequencies are attenuated.
Over all a very well done tut, good speaking voice, no distracting use of “A’s” “Um’s” etc., and most of all: planned out, well organized, succinct and to the point. This should be <b><i>really</;i></b> fun!
Yes, finally! Python Tuts on Nettuts! Thank you so much for this great intro. Looking forward to read/see more – maybe sometime also Django or even Django CMS?
Coming from a PHP background, I initially found it difficult to make the transition to Python or Ruby (still do). A big stumbling block has been working on a Windows machine for development. WAMP makes it dead simple to do real PHP programming, but it’s not as intuitive with Python or Ruby. (One surprising thing that helped was spending some time really learning how JavaScript works).
I actually have considered switching to an Apple based platform for my main development machines since it seems to provide better native support for these languages while still supporting the multimedia apps for graphics, music etc I use daily. Any Web programmers want to chime in on development environment preferences for Ruby or Python?
I think once you get the basic environment setup it’s not much different. Although I think setting up the environment is made easier in things like *nix and OSX, but it can be done pretty simply on Windows too.
Finally a Python tut. Really nice. I hope you’ll be more frequent with posting the next parts.
Looking forward to your next tutorials!!
can your editor provide a download link for the video?
Guyss i am very happy thats you guys have started this series..i hope and want this series should be more frequent..and i will love if you guys follow this series towards “DJANGO”..
Well done nettuts..and thanks
Python baby, I am coming ;)
Yeeesss! Finally! :)
Expecting the next one :P
Great beginners tutorial.
Can’t wait till the next one, keep them coming.
Looks like everyone has been dying to learn Python/Django.
To get NetTuts to really focus on this series, we need to make this article incredibly popular for them. I suggest you share this article with every Tom, Dick, and Hairy you can.
I’m sure a lot of you are fervently scratching your necks right now wanting more follow-ups to this, so I’ll give you something to hold you over now that you know how to create and run Python programs.
If this comment looks all screwed up it’s because I don’t know tuts+ comment shortcode and I can’t edit it.
Python functions look like this:
def say_hello(first_name, last_name):
print “Hello, ” + first_name + ” ” + last_name + “!”
say_hello(“Tobey”, “Macguire”)
Output: Hello, Tobey Macguire!
(relevant: http://bit.ly/aDOn9i)
…
If you’ve ever seen a Python file that starts off with something like this:
#!/usr/bin/python
…it’s trying to tell Unix systems to look for the Python interpreter there. If a simple .py file doesn’t work on a Unix system, chances are you haven’t included this line.
…
If you’ve ever seen a Python file with something like this in it:
import os
import math
…it’s loading libraries of functions for your use. This way you don’t end up with a huge, bloated application, and can just import the pre-made functions you’ll actually use.
For instance, if you’re making a dice-rolling program that picks a random int between 1 and 6, you need to import the Random module first, or else… it just won’t work.
import random
print random.randint(1,6)
There are tons of these modules you can import and use to do anything and everything.
Anyway, hope this comment doesn’t look fubar. And I really hope this series continues to kick ass and that Giles do a follow-up “Django from Scratch” series. After that, I’d be completely happy with Nettuts+ forever.
Hello w1sh, thank you for the really useful comment. I executed that function code – it felt good, and the couple of things you said about importing and finding the interpreter were good bits of knowledge. I wish there were more comments like yours :)
I’m really happy to follow this session, I knew the basics of python from thenewboston on Youtube but I’m sort of lost, I can’t realize where i stand! so thank you and I wish you the best.
Interesting tut, until 5:00 when the video cuts off and just keeps replaying an advert! :(
Yes, give us more Python/Django tutorials please!
awesome intro to python! cant wait for the next few videos. i always found that the intro videos are the most important since getting the environement and runtime setup can be a pain
Sorry to toss in my opinion, but I disagree. It seems incredibly easy to get set up and going.
I understand it’s a necessity, but I think it’s been covered and if not, Google will return a billion results for getting started.
What’s more elusive and important is how to tie Python in with the web.
When Giles said he was going to show us how to do that, I about cried…
Seriously Nettuts, I’ll rejoin premium if you guys have a series on, “Django from Scratch”.
As would I.
(join, not rejoin as I’ve yet to become a member)
Downloadable version without ads for premium members would be nice :)
I really want to learn Python and here comes this series of Python lessons. Looking forward to the next one. Thanks Giles and Nettuts!
Interesting thumb image choice. Python gets its name from Monty Python. :)
Glad to see Python on NetTuts as well!
P.S. – run
import this
On the interpreter. Zen!
I would rather like to see some iOS dev tuts…please!
thats awesome, keep going
my feed back
13 mints per video is not enough
suppose you will dive in Django as it is web related
He mentioned he was going to go into Django. Let’s just hope he’s reeeally, really, thorough. I would love to see a “Django from Scratch” series.
Thanks,
Your tutorial is Great
Python is awesome, i really love the language, but I don’t have any projects to work with it. But when I have the chance to script anything I always do it with python. Even simple things like: ‘one two three’.split() i use to create the lists and use it as arrays in other languages.
What is really annoying in python for mac is to install PIL, it would be really nice to teach the newcomers how to do it.
Bruno, PIL on the Mac (Snow Leopard) is difficult because the PIL module is 32bit. The easiest way to get going is to install a 32bit python (< version 3) to run along side the built in version. Then use a python virtual environment to install the PIL module. You'll need to look up using virtual environments, but it is well worth learning. Once you do, it's easy to use.
“we’re doing one of these a week” – Giles
This tut was posted May 5th. It’s May 12th!!! DEAR LORD!!! *shoots himself in the face*
Seriously though, I’m Jonesin’ for some Python… please please please teach me Django! :(
The tutorial isn’t bad. I am just curious about how you are going to teach us a high level programming language with one short video a week. Don’t get me wrong -> I will watch them all. Thank you for your work! Can’t wait for part two! :-)
ohh thanks I was waiting for this for a long time!
Hi. Thanks for the lesson. Just to let you know though, when I watched it on my iphone the video was too wide and so I could only see the end of each line of code. I know watching it on an iPhone isn’t the best idea but it’s what I carry around with me for podcasts…
Looking forward to the next episode.
The author bailed or what? He promised 1 every week….