Skip to content
Python and Data Primer / Python Foundations

Python Syntax and Control Flow

A position rule must specify when to buy, sell or stay flat. Python comparisons and branches express that decision; loops apply it to several observations. This lesson builds a small signal rule and traces its output. You will later put the rule in a function and check it with tests.
Learning objectives. By the end of this note you should be able to:
  • assign and combine numbers, strings and Boolean values;
  • write an if/elif/else decision;
  • repeat a calculation with a for loop;
  • trace a short program and predict its output.

In this lesson

  1. Values, names and expressions
  2. Branch when the market state changes
  3. Repeat over observations
  4. A minimal mental model
  5. Trace the position decision

This lesson is part of a free topic. Create a free account, no card needed, to read it in full with worked examples and exercise solutions.

Read it free