Important Notice:

Constants in Python

Constants in Python

3 views 1 min read

Constants in Python (पायथन में कॉन्स्टैंट्स) :-

Constant (कॉन्स्टैंट) वह Variable (वैरिएबल) होता है जिसकी Value (मान) पूरे Program के Execution (निष्पादन) के दौरान सामान्यतः (Normally) नहीं बदली जाती।

Python में Constants के लिए कोई अलग Keyword (कीवर्ड) जैसे const उपलब्ध नहीं है। इसलिए Python में Constants को केवल Naming Convention (नामकरण परंपरा) के माध्यम से दर्शाया जाता है।

Python की Convention के अनुसार Constant का नाम UPPERCASE (बड़े अक्षरों) में लिखा जाता है, ताकि यह स्पष्ट हो सके कि उसकी Value को बदलना नहीं चाहिए।

English

A Constant is a variable whose value is intended to remain unchanged throughout the execution of a program.

Python does not provide a special keyword such as const to create constants. Instead, constants are represented using a naming convention.

According to Python conventions, constant names are written in UPPERCASE letters to indicate that their values should not be changed.

Syntax (सिंटैक्स)-

CONSTANT_NAME = value

Example 1-

PI = 3.14159
MAX_SPEED = 120
GST_RATE = 18
 
Example 2 -
PI = 3.14159
radius = 5
area = PI * radius * radius
print(area)

Related Notes