Python variables bind names to objects—no int x = 5 declarations. Django settings, model fields, and view context all use Python's dynamic typing with optional type hints in modern codebases.
Common types in Django code
str— titles, slugs, CharField valuesint— primary keys, counts, IntegerFieldbool— flags, BooleanField, permission checkslist,dict— querysets converted to lists, template contextNone— missing optional fields, empty querysets
Truthy and falsy
Empty strings, empty lists, 0, and None are falsy—useful in templates and if queryset: checks. A queryset with rows is truthy even before you iterate.
Important interview questions and answers
- Q: Mutable vs immutable in Django?
A: Strings and tuples are immutable; lists and dicts are mutable—avoid mutating shared default arguments in model methods. - Q: What type is a model instance?
A: An instance of your model class (subclass ofmodels.Model), not a plain dict. - Q: Type hints in Django?
A: Optional but growing—helps IDEs and mypy in larger codebases.
Self-check
- Which values are falsy in Python?
- What type does
Article.objects.count()return?