pyai.docs

Foundations › 1 of 14

Variables & Types

Python's core data types and dynamic typing.

Python is dynamically typed: a name is bound to an object, and the object carries the type. Use type hints to document intent — essential in large ML codebases.

python
lr: float = 3e-4
epochs: int = 10
model_name: str = "resnet50"
use_gpu: bool = True

print(type(lr), f"{lr:.0e}")
# output
<class 'float'> 3e-04
Tip: f-strings support format specs: f"{loss:.4f}", f"{acc:.1%}", f"{n:,}".

⚡ Quick check

  • ✓ int, float, str, bool, None
  • ✓ Type hints: x: int = 1
  • ✓ f"{x:.3f}" for formatting