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.
Choosing a Version
"It's important to choose the right version."
There are two versions of Python that are currently being developed:
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
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
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
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.
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.
Envato Tuts+ tutorials are translated into other languages by our community members—you can be involved too!Translate this post