{"id":39208,"date":"2025-11-08T08:25:50","date_gmt":"2025-11-08T16:25:50","guid":{"rendered":"https:\/\/cloudinary.com\/blog\/?p=39208"},"modified":"2025-11-08T08:25:51","modified_gmt":"2025-11-08T16:25:51","slug":"how-to-represent-infinity-in-python","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python","title":{"rendered":"How to Represent Infinity in Python?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">You will often see developers use a special sentinel for unbounded ranges, priority queues, or shortest-path algorithms. Python makes this straightforward, but the details can trip you up when you mix in JSON, Decimal, NumPy, or sorting edge cases.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Question:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>How to represent infinity in Python, both positive and negative? What are the practical differences between using float(&#8216;inf&#8217;) and math.inf? How do I check for it, sort with it, serialize it to JSON, and work with it in Decimal or NumPy without surprises?<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Answer:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The canonical way to represent infinity in Python uses a special floating point value <code>float(\u201cinf)<\/code>. You can create positive and negative infinity like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">import math\n\npos_inf = float(<span class=\"hljs-string\">'inf'<\/span>)\u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># Positive infinity<\/span>\nneg_inf = float(<span class=\"hljs-string\">'-inf'<\/span>) \u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># Negative infinity<\/span>\nalso_inf = math.inf \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># Same as float('inf')<\/span>\n\n<span class=\"hljs-keyword\">print<\/span>(pos_inf == also_inf)\u00a0 \u00a0 <span class=\"hljs-comment\"># True<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">How infinity behaves<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Comparisons: <\/strong>any finite number n satisfies neg_inf &lt; n &lt; pos_inf.<\/li>\n\n\n\n<li><strong>Arithmetic: <\/strong>inf + 1 is inf, but inf &#8211; inf is NaN. Always guard for NaN.<\/li>\n\n\n\n<li><strong>Checks:<\/strong> use <code>math.isinf(x)<\/code>, <code>math.isfinite(x)<\/code>, <code>math.isnan(x)<\/code>.<\/li>\n<\/ul>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">import math\n\nx = float(<span class=\"hljs-string\">'inf'<\/span>)\n<span class=\"hljs-keyword\">print<\/span>(x &gt; <span class=\"hljs-number\">10<\/span>**<span class=\"hljs-number\">30<\/span>) \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># True<\/span>\n<span class=\"hljs-keyword\">print<\/span>(math.isinf(x))\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># True<\/span>\n<span class=\"hljs-keyword\">print<\/span>(math.isfinite(x)) \u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># False<\/span>\n<span class=\"hljs-keyword\">print<\/span>((x - x))\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># nan<\/span>\n<span class=\"hljs-keyword\">print<\/span>(math.isnan(x - x))\u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># True<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Sorting and sentinels<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Infinity is useful when sorting values where some entries are missing or should sort to the end.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">data = &#91;<span class=\"hljs-number\">3<\/span>, None, <span class=\"hljs-number\">7<\/span>, <span class=\"hljs-number\">-2<\/span>, None]\n\n<span class=\"hljs-comment\"># Move None to the end by substituting +inf for the sort key<\/span>\nsorted_data = sorted(data, key=lambda v: v <span class=\"hljs-keyword\">if<\/span> v is not None <span class=\"hljs-keyword\">else<\/span> float(<span class=\"hljs-string\">'inf'<\/span>))\n<span class=\"hljs-keyword\">print<\/span>(sorted_data)\u00a0 <span class=\"hljs-comment\"># &#91;-2, 3, 7, None, None]<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Clamping and unbounded defaults<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If there&#8217;s no boundary, use infinity in your function parameters or algorithms.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">def clamp(x, low=-float(<span class=\"hljs-string\">'inf'<\/span>), high=float(<span class=\"hljs-string\">'inf'<\/span>)):\n\u00a0 \u00a0 <span class=\"hljs-keyword\">if<\/span> x &lt; low:\n\u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-keyword\">return<\/span> low\n\u00a0 \u00a0 <span class=\"hljs-keyword\">if<\/span> x &gt; high:\n\u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-keyword\">return<\/span> high\n\u00a0 \u00a0 <span class=\"hljs-keyword\">return<\/span> x\n\n<span class=\"hljs-keyword\">print<\/span>(clamp(<span class=\"hljs-number\">10<\/span>, high=<span class=\"hljs-number\">5<\/span>))\u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># 5<\/span>\n<span class=\"hljs-keyword\">print<\/span>(clamp(<span class=\"hljs-number\">10<\/span>))\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># 10\u00a0 (no bounds)<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Decimal and Fraction<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Decimal: <\/strong>Supports infinities explicitly.<\/li>\n\n\n\n<li><strong>Fraction: <\/strong>Does not support infinity.<\/li>\n<\/ul>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">from decimal import Decimal\n\nd_inf = Decimal(<span class=\"hljs-string\">'Infinity'<\/span>)\nd_ninf = Decimal(<span class=\"hljs-string\">'-Infinity'<\/span>)\n<span class=\"hljs-keyword\">print<\/span>(d_inf &gt; Decimal(<span class=\"hljs-string\">'1e999'<\/span>))\u00a0 <span class=\"hljs-comment\"># True<\/span>\n\n<span class=\"hljs-comment\"># Fractions do not have an infinity representation<\/span>\n<span class=\"hljs-comment\"># Fraction(1, 0) would raise ZeroDivisionError<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">NumPy<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">NumPy has numpy.inf and compatible checks.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">import numpy <span class=\"hljs-keyword\">as<\/span> np\n\narr = np.<span class=\"hljs-keyword\">array<\/span>(&#91;<span class=\"hljs-number\">1.0<\/span>, np.inf, -np.inf, np.nan])\n<span class=\"hljs-keyword\">print<\/span>(np.isinf(arr))\u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># &#91;False\u00a0 True\u00a0 True False]<\/span>\n<span class=\"hljs-keyword\">print<\/span>(np.isfinite(arr)) \u00a0 <span class=\"hljs-comment\"># &#91; True False False False]<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">JSON and persistence pitfalls<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The JSON standard does not include infinity or NaN. Python\u2019s <code>json.dumps<\/code> will emit non-standard <code>Infinity<\/code> by default, which some parsers reject. Set <code>allow_nan=False<\/code> or sanitize values.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">import json, math\n\npayload = {<span class=\"hljs-string\">\"max\"<\/span>: float(<span class=\"hljs-string\">'inf'<\/span>)}\n\n<span class=\"hljs-keyword\">print<\/span>(json.dumps(payload)) \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># {\"max\": Infinity}\u00a0 not strict JSON<\/span>\n<span class=\"hljs-keyword\">try<\/span>:\n\u00a0 \u00a0 json.dumps(payload, allow_nan=<span class=\"hljs-keyword\">False<\/span>) \u00a0 <span class=\"hljs-comment\"># raises ValueError<\/span>\nexcept ValueError:\n\u00a0 \u00a0 pass\n\ndef sanitize_numbers(x):\n\u00a0 \u00a0 <span class=\"hljs-keyword\">if<\/span> isinstance(x, float) <span class=\"hljs-keyword\">and<\/span> (math.isinf(x) <span class=\"hljs-keyword\">or<\/span> math.isnan(x)):\n\u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-keyword\">return<\/span> None\n\u00a0 \u00a0 <span class=\"hljs-keyword\">if<\/span> isinstance(x, dict):\n\u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-keyword\">return<\/span> {k: sanitize_numbers(v) <span class=\"hljs-keyword\">for<\/span> k, v in x.items()}\n\u00a0 \u00a0 <span class=\"hljs-keyword\">if<\/span> isinstance(x, <span class=\"hljs-keyword\">list<\/span>):\n\u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-keyword\">return<\/span> &#91;sanitize_numbers(v) <span class=\"hljs-keyword\">for<\/span> v in x]\n\u00a0 \u00a0 <span class=\"hljs-keyword\">return<\/span> x\n\n<span class=\"hljs-keyword\">print<\/span>(json.dumps(sanitize_numbers(payload)))\u00a0 <span class=\"hljs-comment\"># {\"max\": null}<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Guardrails for user input<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If untrusted input can flow into numeric code, block infinities and <code>NaNs<\/code> to avoid undefined math.:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">def ensure_finite(x: float) -&gt; float:\n\u00a0 \u00a0 <span class=\"hljs-keyword\">if<\/span> not math.isfinite(x):\n\u00a0 \u00a0 \u00a0 raise ValueError(<span class=\"hljs-string\">\"Expected a finite number\"<\/span>)\n\u00a0 \u00a0 <span class=\"hljs-keyword\">return<\/span> x<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Using infinity safely with Cloudinary workflows<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Python image or video pipelines, you might treat a missing upper bound as infinity and then clamp before generating delivery URLs. This avoids sending invalid values to APIs and ensures safe transforms.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">import math\nfrom cloudinary.utils import cloudinary_url\n\ndef build_limited_url(public_id: str, target_w: float):\n\u00a0 \u00a0 <span class=\"hljs-comment\"># Treat infinity as \"no limit,\" but hard cap to a safe maximum<\/span>\n\u00a0 \u00a0 MAX_W = <span class=\"hljs-number\">4096<\/span>\n\u00a0 \u00a0 width = MAX_W <span class=\"hljs-keyword\">if<\/span> not math.isfinite(target_w) <span class=\"hljs-keyword\">else<\/span> int(min(target_w, MAX_W))\n\u00a0 \u00a0 url, _ = cloudinary_url(public_id, transformation=&#91;{<span class=\"hljs-string\">\"crop\"<\/span>: <span class=\"hljs-string\">\"limit\"<\/span>, <span class=\"hljs-string\">\"width\"<\/span>: width}])\n\u00a0 \u00a0 <span class=\"hljs-keyword\">return<\/span> url\n\n<span class=\"hljs-keyword\">print<\/span>(build_limited_url(<span class=\"hljs-string\">\"sample.jpg\"<\/span>, float(<span class=\"hljs-string\">'inf'<\/span>))) \u00a0 <span class=\"hljs-comment\"># uses width=4096<\/span>\n<span class=\"hljs-keyword\">print<\/span>(build_limited_url(<span class=\"hljs-string\">\"sample.jpg\"<\/span>, <span class=\"hljs-number\">1200.0<\/span>)) \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># uses width=1200<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">TL;DR<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Infinity in Python: <code>float('inf')<\/code>, <code>float('-inf')<\/code>, or <code>math.inf<\/code>.<\/li>\n\n\n\n<li>Check with <code>math.isinf<\/code> and <code>math.isfinite<\/code>. Beware that <code>inf - inf<\/code> yields NaN.<\/li>\n\n\n\n<li>JSON does not support Infinity; sanitize or replace before serialization.<\/li>\n\n\n\n<li>Use infinity as a clean sentinel for sorting and unbounded ranges, and clamp before generating URLs or transformations.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Learn More<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/cloudinary.com\/tools\/image-to-jpg\">Image to JPG<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudinary.com\/tools\/jpg-to-webp\">JPG to WebP<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudinary.com\/tools\/png-to-webp\">PNG to WebP<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudinary.com\/guides\/video\/video-as-a-service\">Video as a Service<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Build smarter media workflows with a developer-first platform. <a href=\"https:\/\/cloudinary.com\/users\/register_free\">Sign up for Cloudinary free<\/a> and start transforming, optimizing, and delivering your assets at scale.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You will often see developers use a special sentinel for unbounded ranges, priority queues, or shortest-path algorithms. Python makes this straightforward, but the details can trip you up when you mix in JSON, Decimal, NumPy, or sorting edge cases.&nbsp; Question: How to represent infinity in Python, both positive and negative? What are the practical differences [&hellip;]<\/p>\n","protected":false},"author":88,"featured_media":39209,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_cloudinary_featured_overwrite":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[423],"class_list":["post-39208","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-questions"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.3 (Yoast SEO v28.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Represent Infinity in Python?<\/title>\n<meta name=\"description\" content=\"You will often see developers use a special sentinel for unbounded ranges, priority queues, or shortest-path algorithms. Python makes this\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Represent Infinity in Python?\" \/>\n<meta property=\"og:description\" content=\"You will often see developers use a special sentinel for unbounded ranges, priority queues, or shortest-path algorithms. Python makes this\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-08T16:25:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-08T16:25:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762619073\/how_to_represent_infinity_in_python_featured_image\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA\" \/>\n\t<meta property=\"og:image:width\" content=\"2000\" \/>\n\t<meta property=\"og:image:height\" content=\"1100\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"damjanantevski\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-to-represent-infinity-in-python#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-to-represent-infinity-in-python\"},\"author\":{\"name\":\"damjanantevski\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#\\\/schema\\\/person\\\/43592e43c12520a1e867d456b1e8cf7e\"},\"headline\":\"How to Represent Infinity in Python?\",\"datePublished\":\"2025-11-08T16:25:50+00:00\",\"dateModified\":\"2025-11-08T16:25:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-to-represent-infinity-in-python\"},\"wordCount\":370,\"publisher\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-to-represent-infinity-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1762619073\\\/how_to_represent_infinity_in_python_featured_image\\\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA\",\"keywords\":[\"Questions\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2025\",\"copyrightHolder\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-to-represent-infinity-in-python\",\"url\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-to-represent-infinity-in-python\",\"name\":\"How to Represent Infinity in Python?\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-to-represent-infinity-in-python#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-to-represent-infinity-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1762619073\\\/how_to_represent_infinity_in_python_featured_image\\\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA\",\"datePublished\":\"2025-11-08T16:25:50+00:00\",\"dateModified\":\"2025-11-08T16:25:51+00:00\",\"description\":\"You will often see developers use a special sentinel for unbounded ranges, priority queues, or shortest-path algorithms. Python makes this\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-to-represent-infinity-in-python#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-to-represent-infinity-in-python\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-to-represent-infinity-in-python#primaryimage\",\"url\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1762619073\\\/how_to_represent_infinity_in_python_featured_image\\\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA\",\"contentUrl\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1762619073\\\/how_to_represent_infinity_in_python_featured_image\\\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA\",\"width\":2000,\"height\":1100},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-to-represent-infinity-in-python#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/cloudinary.com\\\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Represent Infinity in Python?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/\",\"name\":\"Cloudinary Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#organization\",\"name\":\"Cloudinary Blog\",\"url\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1649718331\\\/Web_Assets\\\/blog\\\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\\\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"contentUrl\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1649718331\\\/Web_Assets\\\/blog\\\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\\\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"width\":312,\"height\":60,\"caption\":\"Cloudinary Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#\\\/schema\\\/person\\\/43592e43c12520a1e867d456b1e8cf7e\",\"name\":\"damjanantevski\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g\",\"caption\":\"damjanantevski\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Represent Infinity in Python?","description":"You will often see developers use a special sentinel for unbounded ranges, priority queues, or shortest-path algorithms. Python makes this","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python","og_locale":"en_US","og_type":"article","og_title":"How to Represent Infinity in Python?","og_description":"You will often see developers use a special sentinel for unbounded ranges, priority queues, or shortest-path algorithms. Python makes this","og_url":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python","og_site_name":"Cloudinary Blog","article_published_time":"2025-11-08T16:25:50+00:00","article_modified_time":"2025-11-08T16:25:51+00:00","og_image":[{"width":2000,"height":1100,"url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762619073\/how_to_represent_infinity_in_python_featured_image\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA","type":"image\/jpeg"}],"author":"damjanantevski","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python"},"author":{"name":"damjanantevski","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/43592e43c12520a1e867d456b1e8cf7e"},"headline":"How to Represent Infinity in Python?","datePublished":"2025-11-08T16:25:50+00:00","dateModified":"2025-11-08T16:25:51+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python"},"wordCount":370,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762619073\/how_to_represent_infinity_in_python_featured_image\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA","keywords":["Questions"],"inLanguage":"en-US","copyrightYear":"2025","copyrightHolder":{"@id":"https:\/\/cloudinary.com\/#organization"}},{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python","url":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python","name":"How to Represent Infinity in Python?","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762619073\/how_to_represent_infinity_in_python_featured_image\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA","datePublished":"2025-11-08T16:25:50+00:00","dateModified":"2025-11-08T16:25:51+00:00","description":"You will often see developers use a special sentinel for unbounded ranges, priority queues, or shortest-path algorithms. Python makes this","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762619073\/how_to_represent_infinity_in_python_featured_image\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762619073\/how_to_represent_infinity_in_python_featured_image\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA","width":2000,"height":1100},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog"},{"@type":"ListItem","position":2,"name":"How to Represent Infinity in Python?"}]},{"@type":"WebSite","@id":"https:\/\/cloudinary.com\/blog\/#website","url":"https:\/\/cloudinary.com\/blog\/","name":"Cloudinary Blog","description":"","publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudinary.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudinary.com\/blog\/#organization","name":"Cloudinary Blog","url":"https:\/\/cloudinary.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","width":312,"height":60,"caption":"Cloudinary Blog"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/43592e43c12520a1e867d456b1e8cf7e","name":"damjanantevski","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3b40c995531fe4d510212a06c9d4fc666d2cb8efbfebc98a94191701accf4817?s=96&d=mm&r=g","caption":"damjanantevski"}}]}},"parsely":{"version":"1.1.0","canonical_url":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python","meta":{"@context":"https:\/\/schema.org","@type":"NewsArticle","headline":"How to Represent Infinity in Python?","url":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python","mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762619073\/how_to_represent_infinity_in_python_featured_image\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA&w=150&h=150&crop=1","image":{"@type":"ImageObject","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762619073\/how_to_represent_infinity_in_python_featured_image\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA"},"articleSection":"Uncategorized","author":[{"@type":"Person","name":"damjanantevski"}],"creator":["damjanantevski"],"publisher":{"@type":"Organization","name":"Cloudinary Blog","logo":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA"},"keywords":["questions"],"dateCreated":"2025-11-08T16:25:50Z","datePublished":"2025-11-08T16:25:50Z","dateModified":"2025-11-08T16:25:51Z"},"rendered":"<meta name=\"parsely-title\" content=\"How to Represent Infinity in Python?\" \/>\n<meta name=\"parsely-link\" content=\"https:\/\/cloudinary.com\/blog\/questions\/how-to-represent-infinity-in-python\" \/>\n<meta name=\"parsely-type\" content=\"post\" \/>\n<meta name=\"parsely-image-url\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762619073\/how_to_represent_infinity_in_python_featured_image\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA&w=150&amp;h=150&amp;crop=1\" \/>\n<meta name=\"parsely-pub-date\" content=\"2025-11-08T16:25:50Z\" \/>\n<meta name=\"parsely-section\" content=\"Uncategorized\" \/>\n<meta name=\"parsely-tags\" content=\"questions\" \/>\n<meta name=\"parsely-author\" content=\"damjanantevski\" \/>","tracker_url":"https:\/\/cdn.parsely.com\/keys\/cloudinary.com\/p.js"},"jetpack_featured_media_url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762619073\/how_to_represent_infinity_in_python_featured_image\/how_to_represent_infinity_in_python_featured_image.jpg?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39208","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/users\/88"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/comments?post=39208"}],"version-history":[{"count":1,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39208\/revisions"}],"predecessor-version":[{"id":39210,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39208\/revisions\/39210"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/39209"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=39208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=39208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=39208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}