Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

Constants in Python: Implementation and Best Practices

Samuel Chan via YouTube

Overview

Coursera Plus Monthly Sale: All Certificates & Courses 40% Off!
Explore the concept of constants in Python through a comprehensive 24-minute video tutorial. Discover when and why to use constants instead of variables, and learn three practical implementations: frozen dataclasses, raising TypeError in __setattr__, and using typing.final. Gain insights into Python's design philosophy regarding constants and understand how to incorporate them into your programming toolkit. Follow along with code examples and explanations of the benefits and advantages of using constants in Python programming.

Syllabus

Intro
Background: const vs var
Why / when to use constants const?
Benefits / Advantages of const
dataclasses' frozen param Frozen dataclasses
raise TypeError in __setattr__
python's design philosophy on const
typing.final / @final decorator
from typing import Final typecheck
summary including const into your python programming toolkit

Taught by

Samuel Chan

Reviews

Start your review of Constants in Python: Implementation and Best Practices

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.