Defining Python Constants for Code Maintainability (Overview)
In programming, the term constant refers to names representing values that don’t change during a program’s execution. Constants are a fundamental concept in programming, and Python developers use them in many cases. However, Python doesn’t have a dedicated syntax for defining constants. In practice, Python constants are just variables that never change.
To prevent programmers from reassigning a name that’s supposed to hold a constant, the Python community has adopted a naming convention: use uppercase letters. For every Pythonista, it’s essential to know what constants are, as well as why and when to use them.
In this video course, you’ll learn how to:
- Properly define constants in Python
- Identify some built-in constants
- Use constants to improve your code’s readability, reusability, and maintainability
- Apply different approaches to organize and manage constants in a project
- Use several techniques to make constants strictly constant in Python
00:00 Defining Python Constants for Code Maintainability
00:04 In programming, the term constant refers to names representing values that don’t change during a program’s execution. Constants are a fundamental concept in programming, and Python developers use them in many cases, but Python doesn’t have a dedicated syntax for defining constants and in practice, Python constants are just variables that never change.
00:27 To prevent programmers from reassigning a name that’s supposed to hold a constant, the Python community has adopted a naming convention of using uppercase letters. For every Pythonista, it’s essential to know what constants are, as well as why and when to use them.
00:42 So in this course, you’ll learn how to: properly define constants in Python, identify some built-in constants, use constants to improve your code’s readability, reusability, and maintainability; apply different approaches to organize and manage constants in a project, and use several techniques to make constants strictly constant in Python.
01:05 By learning to define and use constants, you’ll dramatically improve your code’s readability, maintainability, and reusability.
01:14 To get the most from this course, you’ll need basic knowledge of Python variables, functions, modules, packages, and namespaces. You’ll also need to know the basics of object-oriented programming in Python.
01:28 Any code that you see running in the REPL will be using the Bpython interpreter. This is a replacement Python interpreter that offers a number of enhancements, including code highlighting and suggestions.
01:39
But any code you see running on screen will work in the Python REPL, which is typically accessed by typing python
or python3
at your terminal or command-line prompt.
01:49 So now you know what’s going to be covered, let’s get started.
Become a Member to join the conversation.