Real Python

Sample Code: Click here to download a Circle class in three versions that shows how named constants replace a hard-coded 3.14.

Almost there! Complete this form and click the button below to gain instant access:

Python Constants: Improve Your Code's Maintainability

Replace Magic Numbers With Named Constants

๐Ÿ”’ No spam. We take your privacy seriously.

ยฉ 2012โ€“2026 Real Python โ‹… Privacy Policy