A price is a
float, a ticker is a str, a "is this trade filled?" flag is a bool — every quantitative object this vault ever manipulates in code starts life as one of a small handful of primitive Python types, combined by a small handful of operators into expressions. This note fixes that vocabulary precisely: the four scalar types, the arithmetic and comparison operators defined on them, operator precedence, and the mechanics of naming a value with a variable. Getting this exactly right matters more than it looks — a beginner's most common early bug (i/j returning a truncated integer instead of a fraction, or = where == was meant) is a type or operator mistake at exactly this level.Learning objectives. By the end of this note you should be able to:
- name Python's four scalar object types and classify any literal by type;
- predict, for a given arithmetic expression, both its type and its value, including the distinction between
/and//; - state operator precedence rules and use parentheses to force a different evaluation order;
- write a correct assignment statement (including multiple assignment) and explain why "a variable is just a name" has consequences beyond this lesson.
In this lesson
- Objects, literals, and scalar types
- Expressions and the arithmetic operators
- Variables and assignment
Before you start
The full lesson, with worked examples and exercise solutions, is for members.
Read the full lessonNew to SelfMadeQuant.com? See membership options or browse the Python for Quantitative Finance syllabus.