{"id":113152,"date":"2025-11-19T12:16:06","date_gmt":"2025-11-19T06:46:06","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/?page_id=113152"},"modified":"2025-11-11T16:43:47","modified_gmt":"2025-11-11T11:13:47","slug":"python-constants","status":"publish","type":"page","link":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/","title":{"rendered":"Python Constants"},"content":{"rendered":"\n<h1 id=\"understanding-python-constants\">Understanding Python Constants<\/h1>\n \n<p>In Python, a <strong>constant<\/strong> is a type of variable whose value is not meant to be changed. You use constants to store values that you know should remain the same throughout your program.<\/p>\n \n<p>Using constants makes your code safer and easier to understand. It helps prevent accidental changes to important data, such as the value of Pi (3.14159) or a maximum number of login attempts (5).<\/p>\n \n<p>Unlike some other programming languages, Python does not have a strict, built-in feature to make variables unchangeable. Instead, Python developers use a <strong>naming convention<\/strong>. This is an agreement among programmers to signal that a variable should be treated as a constant.<\/p>\n\n<h3 id=\"the-naming-convention-for-constants\">The Naming Convention for Constants<\/h3>\n<p>The rule is simple and important: To declare a constant, you write the variable name in <strong>all uppercase letters<\/strong>. Use an <strong>underscore (<code>_<\/code>)<\/strong> to separate words.<\/p>\n \n<ul>\n    <li><code>PI = 3.14159<\/code><\/li>\n    <li><code>TAX_RATE = 0.07<\/code><\/li>\n    <li><code>WEBSITE_NAME = \"My Awesome Site\"<\/code><\/li>\n    <li><code>MAX_LOGIN_ATTEMPTS = 3<\/code><\/li>\n<\/ul>\n\n\n<h2 id=\"exercise-1-define-and-print-a-constant\">Exercise 1: Define and Print a Constant<\/h2>\n<p>We will start with a simple example. Create a constant named <code>PI<\/code> with the value <code>3.14159<\/code> and then print it to the console.<\/p>\n \n<div class=\"code-editor-container\">\n    <div id=\"editor-1\" class=\"python-code-editor\"># Your code here!\n# 1. Create a constant named PI\n# 2. Print the PI constant\n<\/div>\n    <div class=\"button-container\">\n        <button class=\"button button-run\" onclick=\"runPythonCode('editor-1', 'output-1')\">Run Code<\/button>\n        <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-1', this)\">Show Example<\/button>\n    <\/div>\n    \n    <div id=\"solution-1\" class=\"code-solution\">\n        <pre><code># This is the example solution\nPI = 3.14159\nprint(\"The value of PI is:\")\nprint(PI)<\/code><\/pre>\n    <\/div>\n    \n    <label for=\"output-1\" class=\"output-label\">Output:<\/label>\n    <pre id=\"output-1\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n\n\n<h2 id=\"exercise-2-testing-the-constant-rule\">Exercise 2: Testing the Constant \"Rule\"<\/h2>\n<p>As we mentioned, constants are a convention, not a strict rule enforced by Python. What happens if you try to change one? Let's find out.<\/p>\n<p>In the box below, define <code>TAX_RATE = 0.05<\/code> and print it. Then, on a new line, re-assign it to <code>0.07<\/code> and print it again.<\/p>\n \n<div class=\"code-editor-container\">\n    <div id=\"editor-2\" class=\"python-code-editor\"># Your code here!\n# 1. Define TAX_RATE\n# 2. Print it\n# 3. Re-assign TAX_RATE to a new value\n# 4. Print it again\n<\/div>\n    <div class=\"button-container\">\n        <button class=\"button button-run\" onclick=\"runPythonCode('editor-2', 'output-2')\">Run Code<\/button>\n        <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-2', this)\">Show Example<\/button>\n    <\/div>\n    \n    <div id=\"solution-2\" class=\"code-solution\">\n        <pre><code>TAX_RATE = 0.05\nprint(f\"The original tax rate is: {TAX_RATE}\")\n\n# Now we try to change it...\nTAX_RATE = 0.07\nprint(f\"The new tax rate is: {TAX_RATE}\")<\/code><\/pre>\n    <\/div>\n    \n    <label for=\"output-2\" class=\"output-label\">Output:<\/label>\n    <pre id=\"output-2\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n \n<div class=\"insight-box\">\n    <strong>Analysis:<\/strong> As you can see, Python allows the value to be changed. This is why the all-caps convention is so important. It is not a rule for the computer; it is a clear signal to human developers that this value should not be modified.\n<\/div>\n\n\n\n<h2 id=\"the-purpose-and-benefits-of-using-constants\">The Purpose and Benefits of Using Constants<\/h2>\n<p>You might wonder, \"If they can be changed, why should I use them?\" Using constants is a critical part of writing clean, professional, and maintainable code. Here\u2019s why:<\/p>\n \n<ul>\n    <li><strong>Readability:<\/strong> Code is much easier to read. Seeing <code>if credits < MIN_CREDITS:<\/code> is much clearer than <code>if credits < 30:<\/code>. The number 30 is a \"magic number\" - its meaning is unclear without context.<\/li>\n    <li><strong>Maintainability:<\/strong> Imagine you used <code>0.05<\/code> as a tax rate in 20 different places in your application. If that rate changes, you must find and replace all 20 instances. With a constant, you only change it <strong>once<\/strong> at the top of your file (e.g., <code>TAX_RATE = 0.06<\/code>).<\/li>\n    <li><strong>Error Prevention:<\/strong> It signals to you and your teammates that \"This value should not be modified.\" This prevents you from *accidentally* changing a value that should always stay the same.<\/li>\n<\/ul>\n\n\n<h2 id=\"knowledge-check-apply-your-skills\">Knowledge Check: Apply Your Skills<\/h2>\n<p>You are building a game. In the editor below, define the necessary variables and constants for the following requirements. Then, print them to see your work.<\/p>\n \n<ul>\n    <li>The player's current score, which starts at 0.<\/li>\n    <li>The game's title, which is \"Super Python Quest\".<\/li>\n    <li>The highest possible score, which is 1,000,000.<\/li>\n    <li>A list of level names: \"The Forest\", \"The Cave\", and \"The Castle\".<\/li>\n<\/ul>\n \n<div class=\"code-editor-container\">\n    <div id=\"editor-4\" class=\"python-code-editor\"># Define your variables and constants here\n# based on the requirements above.\n\n# ...\n\n# Now, print them all to check your work\n# print(f\"Game Title: {your_constant_here}\")\n# print(f\"Player Score: {your_variable_here}\")\n# ...\n<\/div>\n    <div class=\"button-container\">\n        <button class=\"button button-run\" onclick=\"runPythonCode('editor-4', 'output-4')\">Run Code<\/button>\n        <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-4', this)\">Show Answer<\/button>\n    <\/div>\n    \n    <div id=\"solution-4\" class=\"code-solution\">\n    <p>Here is how a professional developer would define these:<\/p>\n    <pre><code># --- Constants ---\n\n# The game's title will not change.\nGAME_TITLE = \"Super Python Quest\"\n\n# The max score is a fixed rule of the game.\nMAX_SCORE = 1000000\n\n# The list of levels is fixed. We use a tuple to make it immutable.\nLEVEL_NAMES = (\"The Forest\", \"The Cave\", \"The Castle\")\n\n\n# --- Variables ---\n\n# The player's score will change often.\nplayer_score = 0\n\n\n# --- Print Check ---\nprint(f\"Game Title: {GAME_TITLE}\")\nprint(f\"Max Score: {MAX_SCORE}\")\nprint(f\"Levels: {LEVEL_NAMES}\")\nprint(f\"Starting Score: {player_score}\")\n\n# Example of changing a variable\nplayer_score = player_score + 50\nprint(f\"Score after first points: {player_score}\")\n<\/code><\/pre>\n<\/div>\n\n<label for=\"output-4\" class=\"output-label\">Output:<\/label>\n<pre id=\"output-4\" class=\"code-output\">Your output will appear here...<\/pre>\n\n<div class=\"cta-final\">\n    <div class=\"cta-final-header\">\n        <span class=\"cta-final-trophy\">\ud83c\udfc6<\/span>\n        <h2 id=\"lesson-completed\">Lesson Completed<\/h2>\n    <\/div>\n    \n    <p class=\"cta-final-intro\">You now understand Python constants and how to use them professionally. Ready to continue your Python mastery?<\/p>\n    \n    <div class=\"cta-final-grid\">\n        <div class=\"cta-final-option\">\n            <div class=\"cta-final-option-header\">\n                <span>\ud83d\udcd8<\/span>\n                <h4 id=\"full-python-course\">Full Python Course<\/h4>\n            <\/div>\n            <p>Master Python with 11+ hours of content, 50+ exercises, real-world projects and get a Certificate.<\/p>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming?utm_source=blog\" class=\"cta-final-button-primary\">Enroll Now<\/a>\n        <\/div>\n        \n        <div class=\"cta-final-option\" id=\"pt-next-lesson-container\">\n            <div class=\"cta-final-option-header\">\n                <span>\ud83d\udcdd<\/span>\n                <h4 id=\"next-lesson\">Next Lesson<\/h4>\n            <\/div>\n            <p id=\"pt-next-lesson-text\">Continue with the next lesson.<\/p>\n            <a href=\"#\" id=\"pt-next-lesson-button\" class=\"cta-final-button-secondary\">Next Lesson \u2192<\/a>\n        <\/div>\n    <\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Understand Python constants and write professional code. Learn uppercase naming, immutability concepts, and best practices with interactive browser exercises.<\/p>\n","protected":false},"author":41,"featured_media":113351,"parent":113156,"menu_order":8,"comment_status":"closed","ping_status":"closed","template":"templates\/python-tutorial.php","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36796,36893],"class_list":["post-113152","page","type-page","status-publish","has-post-thumbnail","hentry","category-software","tag-python","tag-python-tutorial"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Learn Python Constants<\/title>\n<meta name=\"description\" content=\"Understand Python constants and write professional code. Learn uppercase naming, immutability concepts, and best practices with interactive browser exercises.\" \/>\n<meta name=\"robots\" content=\"index, nofollow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Constants\" \/>\n<meta property=\"og:description\" content=\"Understand Python constants and write professional code. Learn uppercase naming, immutability concepts, and best practices with interactive browser exercises.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1408\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-constants\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-constants\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Python Constants\",\"datePublished\":\"2025-11-19T06:46:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-constants\\\/\"},\"wordCount\":593,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-constants\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/python-constants.webp\",\"keywords\":[\"python\",\"python-tutorial\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-constants\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-constants\\\/\",\"name\":\"Learn Python Constants\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-constants\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-constants\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/python-constants.webp\",\"datePublished\":\"2025-11-19T06:46:06+00:00\",\"description\":\"Understand Python constants and write professional code. Learn uppercase naming, immutability concepts, and best practices with interactive browser exercises.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-constants\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-constants\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-constants\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/python-constants.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/python-constants.webp\",\"width\":1408,\"height\":768,\"caption\":\"Python Constants\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-constants\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Tutorial\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Constants\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Learn Python Constants","description":"Understand Python constants and write professional code. Learn uppercase naming, immutability concepts, and best practices with interactive browser exercises.","robots":{"index":"index","follow":"nofollow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/","og_locale":"en_US","og_type":"article","og_title":"Python Constants","og_description":"Understand Python constants and write professional code. Learn uppercase naming, immutability concepts, and best practices with interactive browser exercises.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","og_image":[{"width":1408,"height":768,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants.webp","type":"image\/webp"}],"twitter_card":"summary_large_image","twitter_site":"@Great_Learning","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Python Constants","datePublished":"2025-11-19T06:46:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/"},"wordCount":593,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants.webp","keywords":["python","python-tutorial"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/","url":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/","name":"Learn Python Constants","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants.webp","datePublished":"2025-11-19T06:46:06+00:00","description":"Understand Python constants and write professional code. Learn uppercase naming, immutability concepts, and best practices with interactive browser exercises.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants.webp","width":1408,"height":768,"caption":"Python Constants"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-constants\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python Tutorial","item":"https:\/\/www.mygreatlearning.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Python Constants"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants.webp",1408,768,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants-150x150.webp",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants-300x164.webp",300,164,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants-768x419.webp",768,419,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants-1024x559.webp",1024,559,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants.webp",1408,768,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants.webp",1408,768,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants-640x768.webp",640,768,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants-96x96.webp",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-constants-150x82.webp",150,82,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Understand Python constants and write professional code. Learn uppercase naming, immutability concepts, and best practices with interactive browser exercises.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/113152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=113152"}],"version-history":[{"count":20,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/113152\/revisions"}],"predecessor-version":[{"id":113179,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/113152\/revisions\/113179"}],"up":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/113156"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/113351"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=113152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=113152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=113152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}