CS 111 › Lesson 1 of 12

Variables, Types & Expressions

Lesson 1 · OKSTEM College · Associate of Science in Computer Science

Variables, Types & Expressions

Python is a dynamically typed language — variables hold references to objects, and the type is determined at runtime.

Core Built-in Types

TypeExampleNotes
int42, -7, 0Arbitrary precision
float3.14, 1e-9IEEE 754 double
boolTrue, FalseSubclass of int
str"hello"Immutable Unicode
NoneTypeNoneAbsence of value
# Assignment x = 42 pi = 3.14159 name = "Alice" is_enrolled = True # Arithmetic operators 10 + 3 # 13 10 - 3 # 7 10 * 3 # 30 10 / 3 # 3.333... (float division) 10 // 3 # 3 (floor division) 10 % 3 # 1 (modulo / remainder) 2 ** 10 # 1024 (exponentiation) # Type checking type(x) # <class 'int'> isinstance(x, int) # True

Python gotcha: Integer division // rounds toward negative infinity: -7 // 2 == -4, not -3.

Lab — Expression Evaluator

Knowledge Check

What does the // operator do in Python?

What type does Python assign to 3.14?

type(True) in Python returns

Which operator gives the remainder of division?

2 ** 8 evaluates to

Next →