🐍
Python For Starters
  • Overview
  • Python for starters
  • Content
  • Foreword
  • Introduction To Python
    • Python Installation
    • Variables
    • Python Data Types
    • Python Data Structures
    • Python numbers
    • Python strings
    • Python Boolean
    • Python constants
    • Python Comments
    • Type Conversion
    • Control flow in python
  • Python Functions
    • Function Definition
    • Function Parameter
    • Recursive Functions
    • Using Global Variables in Functions
    • Lambda Functions
  • What are Data Structures
    • Python Lists
    • Python Tuples
    • Python Dictionaries
    • Python Sets
    • Iterable in python
    • Python Map, Filter & Reduce Functions
  • Error handling in Python
  • Loop ... Else Clause, Partial Functions & Type Hints
    • Partial Functions
    • Type Hints
  • Python Modules
  • Python Libraries & Packages
    • Python Packages
  • Directory & IO
    • Python IO Module
  • Pyenv
  • Virtual Environments
    • Pipenv
    • Virtualenv
  • Object Oriented Programming in Python
    • Class
    • Class Methods
    • Python Class Inheritance
    • Python Class Polymorphism
    • Python special methods
  • Appendix
  • Contributing
Powered by GitBook
On this page
  1. Introduction To Python

Python constants

Constants

In Python, a constant is a variable whose value remains unchanged throughout the program. Constants are usually defined in all capital letters so that they can be easily identified.

In Python, there is no built-in support for constants. However, you can define constants in your program by assigning a value to a variable and then not changing the value of the variable.

Here is an example of how to define and use constants in Python:

"""
Constants -> Python doesn't support constants, 
but we use the uppercase letters to show 
that it is a constant
"""

WEBSITE_HOST = 'https://solomonmarvel.com'

print(WEBSITE_HOST)


# code example

PI = 3.14159265

def calculate_area(radius):
  return PI * radius * radius

radius = 10
area = calculate_area(radius)
print(f"The area of a circle with radius {radius} is {area}")

PreviousPython BooleanNextPython Comments

Last updated 1 year ago