This is a concise Python 3 programming tutorial for people who think that reading is boring. I try to show everything with simple code examples; there are no long and complicated explanations with fancy words. If you have never programmed before click here to find out what programming is like and get started.
This tutorial is aimed at people with no programming experience at all or very little programming experience. If you have programmed a lot in the past using some other language you may want to read the official tutorial instead.
You can use Python 3.3 or any newer Python with this tutorial. Don't use Python 2. If you write a Python 2 program now someone will need to convert it to Python 3 later, so it's best to just write Python 3 to begin with. Python 3 code will work just fine in Python 4, so you don't need to worry about that. Python 2 also has horrible Unicode problems, so it's difficult to write Python 2 code that works correctly with non-English characters (like π and ♫).
The tutorial consists of two sections:
This section will get you started with using Python and you'll be able to learn more about whatever you want after studying it.
- What is programming?
- Installing Python
- Getting started with Python
- ThinkPython: The way of the program
- Variables, Booleans and None
- Using functions
- Setting up an editor
- If, else and elif
- Handy stuff with strings
- Lists and tuples
- Loops
- Trey Hunner: zip and enumerate
- Dictionaries
- Defining functions
- Writing a larger program
- What is true?
- Files
- Modules
- Exceptions
- Classes
- Docstrings
If you want to learn more advanced techniques, you can also read this section. Most of the techniques explained here are great when you're working on a large project, and your code would be really repetitive without these things.
You can experiment with these things freely, but please don't use these techniques just because you know how to use them. Prefer the simple techniques from the Basics part instead when possible. Simple is better than complex.
- Answers for excercises in basics and advanced sections
- The TODO list