Shiklo Tools
PDF40
Image20
Calculators & Converters25
Text & Writing13
Developer26
Video14
Audio14
Document14
Data & Spreadsheet12
Web & SEO9
OCR & Scanning5
Archive & File12
Security & Privacy23
Health & Medical29
QR & Barcode5

Python Tutorial

Python is one of the most popular programming languages in the world. It is used to build websites, to analyse data, to train artificial intelligence, to automate boring work, to control robots and to teach programming in schools and universities. Its code reads almost like English, so beginners can write useful programs in their first hour, and the same language grows with you to very large projects.

This tutorial takes you from your very first program to functions, classes, files and working with data. Each topic explains one idea in plain words and shows short example programs. Every example has a Try it in the editor button: it opens the program in our online Python editor in a new tab, where you can change it, run it and see what happens. Nothing needs to be installed: real Python runs inside your browser.

How this tutorial is organised

The topics follow the order most courses use, and each one builds on the ones before it.

  • Basics: the shape of a program, output, comments, variables, data types, numbers, strings, operators, user input, decisions, loops, lists, tuples, sets and dictionaries.
  • Functions and modules: writing your own functions, arguments, scope, recursion, lambda, and using modules such as math, random and datetime.
  • Objects and errors: handling errors with try and except, classes and objects, inheritance, polymorphism, iterators and generators.
  • Files and data: reading and writing files, JSON, regular expressions, the collections module, turtle graphics, NumPy, pandas and matplotlib.

Use the topic list to jump anywhere, and the Previous and Next buttons to read the course in order.

Your first look at Python

Here is a complete Python program. Press Try it in the editor, then Run, and the terminal shows its output.

print("Hello, World!")
Output
Hello, World!

That is the whole program: one line. There is no extra code around it, no semicolon at the end and nothing to compile first. Python reads your file from the top and runs each line in turn. The next topic, Get Started, explains how this works.

Tips for learning Python

  • Type the examples yourself. Reading code is not the same as writing it. Small typing mistakes teach you to read Python's messages.
  • Change things and run again. Change a number, remove a bracket, print one more line. Predict what will happen first, then check.
  • Read the error messages. Python tells you the file, the line and the kind of error. Our editor also adds a hint in plain words and marks the line.
  • Try ideas in the interpreter. Type python3 in the terminal and you can test one line at a time: every expression shows its value at once.

Practice exercises

  1. Run the example above, then change the text so it prints your own name.
  2. Add a second print line that prints the name of your city.
  3. Remove the closing bracket of the print line, run the program and read the error and the hint. Put the bracket back.