Python: getting started

Lesson 01 · 10 min

Indentation, names, types as a habit

There are no block braces. A block is defined by indentation. You don't write the type up front, but the value still has one.

In Python a block isn't in { }. After : comes a new line and a 4-space indent. Mix tabs and spaces and you get an error, not "well, it almost works". A variable name doesn't carry a type: n = 1 can later become n = "one". The value has a type, not the box.

A branch
AI

You can ask about this rule«No declaring in advance»

  • # is a comment to the end of the line.
  • None means "nothing"; don't confuse it with 0 and "". In a condition None is false.
  • A string and a number don't add silently: "n=" + 1 fails. You need str(1) or an f-string f"n={n}".
AI

You can ask about this point«Lesson summary»

Check

Lock it in before you move on

  1. 1. How is the body of an if marked in Python?

  2. 2. What does "n=" + 1 do?

  3. 3. None is closer to

PracticeSolve the lesson tasksA few short tasks in the editor. Check your code right away and see where it goes wrong.Start practice