{"id":39179,"date":"2025-11-07T13:51:14","date_gmt":"2025-11-07T21:51:14","guid":{"rendered":"https:\/\/cloudinary.com\/blog\/?p=39179"},"modified":"2025-11-07T13:51:15","modified_gmt":"2025-11-07T21:51:15","slug":"how-does-the-or-operator-work-in-python","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python","title":{"rendered":"How does the or operator work in Python?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In Python threads and dev chats, one of the most common logic questions pops up when writing config handling or fallbacks: why does this expression return a string instead of a boolean, and why did my function never run? That often traces back to Python\u2019s or operator and how it evaluates expressions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Question:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><em>I keep seeing code like <code>value = user_value or default_value<\/code>. I thought or returns a boolean, but in Python it seems to return one of the operands. Also, I hear it uses short-circuit evaluation and has tricky precedence with and and with things like NumPy arrays. How does the or operator work in Python? What are common patterns and pitfalls I should know, and how should I write safer code with it?<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Answer:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Python\u2019s <code>or<\/code> is a logical operator that returns one of its operands, not necessarily a boolean. It evaluates operands left to right and uses short-circuit evaluation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What <code>or<\/code> returns<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It returns the first truthy operand, if any.<\/li>\n\n\n\n<li>If all operands are falsy, it returns the last operand.<\/li>\n<\/ul>\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\"><span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-number\">0<\/span> <span class=\"hljs-keyword\">or<\/span> <span class=\"hljs-string\">\"fallback\"<\/span>)\u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># \"fallback\"\u00a0 (0 is falsy)<\/span>\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"hello\"<\/span> <span class=\"hljs-keyword\">or<\/span> <span class=\"hljs-string\">\"world\"<\/span>) \u00a0 \u00a0 <span class=\"hljs-comment\"># \"hello\" \u00a0 \u00a0 (first operand is truthy)<\/span>\n<span class=\"hljs-keyword\">print<\/span>(&#91;] <span class=\"hljs-keyword\">or<\/span> {}) \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span class=\"hljs-comment\"># {}\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 (both falsy, returns last)<\/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<p class=\"wp-block-paragraph\">Truthy means any value that is not considered falsy. Falsy values include <code>False<\/code>, <code>None<\/code>, <code>0<\/code>, empty sequences or collections like <code>\"\"<\/code>, <code>[]<\/code>, <code>()<\/code>, <code>{}<\/code>, and empty sets.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Short-circuit behavior<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If the left operand is truthy, Python does not evaluate the right operand.<\/li>\n\n\n\n<li>If the left operand is falsy, Python evaluates and returns the right operand.<\/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\">def expensive():\n\u00a0 \u00a0 <span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"expensive() called\"<\/span>)\n\u00a0 \u00a0 <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">\"result\"<\/span>\n\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-keyword\">True<\/span> <span class=\"hljs-keyword\">or<\/span> expensive()) \u00a0 <span class=\"hljs-comment\"># True, function never called<\/span>\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-keyword\">False<\/span> <span class=\"hljs-keyword\">or<\/span> expensive())\u00a0 <span class=\"hljs-comment\"># \"result\", function is called<\/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\">Operator precedence<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>and<\/code> has higher precedence than <code>or<\/code>. So <code>a or b<\/code> and <code>c<\/code> is parsed as <code>a or (b and c)<\/code>. When in doubt, add parentheses.<\/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\">def expensive():\n\u00a0 \u00a0 <span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"expensive() called\"<\/span>)\n\u00a0 \u00a0 <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">\"result\"<\/span>\n\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-keyword\">True<\/span> <span class=\"hljs-keyword\">or<\/span> expensive()) \u00a0 <span class=\"hljs-comment\"># True, function never called<\/span>\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-keyword\">False<\/span> <span class=\"hljs-keyword\">or<\/span> expensive())\u00a0 <span class=\"hljs-comment\"># \"result\", function is called<\/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\">Common patterns<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Fallbacks:<\/strong> <code>config_value = user_value<\/code> or <code>default_value<\/code><\/li>\n\n\n\n<li><strong>Function results with fallback:<\/strong> <code>data = fetch() or compute_fallback(<\/code>) uses short-circuiting to avoid calling the fallback when not needed.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Pitfalls and safer alternatives<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Falsy vs None: <\/strong>if <code>0<\/code> is a valid input, <code>x = user_value<\/code> or <code>10<\/code> will replace <code>0<\/code>. Use explicit checks:<br><br><code>x = 10 if user_value is None else user_value<\/code><\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>With collections and strings:<\/strong> empty values are falsy. If an empty string is a valid value, do not use <code>or<\/code> for defaults.<\/li>\n\n\n\n<li><strong>With NumPy or Pandas: <\/strong><code>or<\/code> does not compare arrays and will raise errors about ambiguous truth values. Use bitwise | or <code>any()\/all()<\/code>:<\/li>\n<\/ul>\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\"><span class=\"hljs-comment\"># Incorrect for arrays:<\/span>\n<span class=\"hljs-comment\"># if arr &gt; 0 or arr &lt; -1: ...<\/span>\n\n<span class=\"hljs-comment\"># Correct:<\/span>\nmask = (arr &gt; <span class=\"hljs-number\">0<\/span>) | (arr &lt; <span class=\"hljs-number\">-1<\/span>)\n<span class=\"hljs-keyword\">if<\/span> mask.any():\n\u00a0 \u00a0 ...\n\n<span class=\"hljs-comment\"># Or for pure booleans:<\/span>\n<span class=\"hljs-keyword\">if<\/span> any(x &gt; <span class=\"hljs-number\">0<\/span> <span class=\"hljs-keyword\">for<\/span> x in arr):\n\u00a0 \u00a0 ...<\/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<ul class=\"wp-block-list\">\n<li><strong>Membership and precedence gotcha:<\/strong><\/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\"><span class=\"hljs-comment\"># Buggy intention: check if ext is \"jpg\" or \"jpeg\"<\/span>\n<span class=\"hljs-keyword\">if<\/span> ext == <span class=\"hljs-string\">\"jpg\"<\/span> <span class=\"hljs-keyword\">or<\/span> <span class=\"hljs-string\">\"jpeg\"<\/span>:\n\u00a0 \u00a0 pass\u00a0 <span class=\"hljs-comment\"># always truthy because \"jpeg\" is truthy<\/span>\n\n<span class=\"hljs-comment\"># Correct:<\/span>\n<span class=\"hljs-keyword\">if<\/span> ext in {<span class=\"hljs-string\">\"jpg\"<\/span>, <span class=\"hljs-string\">\"jpeg\"<\/span>}:\n\u00a0 \u00a0 ...<\/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\">Using <code>or<\/code> in a Python workflow with Cloudinary<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Once you understand or, you can use it to set safe defaults when preparing media for upload or delivery. For example, pick a default output format and quality from environment variables, then upload and build a delivery URL.&nbsp;<\/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 os\nfrom cloudinary import config, uploader, CloudinaryImage\n\n<span class=\"hljs-comment\"># Configure from env or use safe defaults with `or`<\/span>\ncloud_name = os.getenv(<span class=\"hljs-string\">\"CLOUD_NAME\"<\/span>) <span class=\"hljs-keyword\">or<\/span> <span class=\"hljs-string\">\"demo\"<\/span>\napi_key = os.getenv(<span class=\"hljs-string\">\"CLOUD_API_KEY\"<\/span>) <span class=\"hljs-keyword\">or<\/span> <span class=\"hljs-string\">\"123456\"<\/span>\napi_secret = os.getenv(<span class=\"hljs-string\">\"CLOUD_API_SECRET\"<\/span>) <span class=\"hljs-keyword\">or<\/span> <span class=\"hljs-string\">\"abcxyz\"<\/span>\n\nconfig(cloud_name=cloud_name, api_key=api_key, api_secret=api_secret, secure=<span class=\"hljs-keyword\">True<\/span>)\n\n<span class=\"hljs-comment\"># Choose format and quality with fallbacks<\/span>\nfmt = os.getenv(<span class=\"hljs-string\">\"IMG_FORMAT\"<\/span>) <span class=\"hljs-keyword\">or<\/span> <span class=\"hljs-string\">\"webp\"<\/span>\nquality = int(os.getenv(<span class=\"hljs-string\">\"IMG_QUALITY\"<\/span>) <span class=\"hljs-keyword\">or<\/span> <span class=\"hljs-number\">80<\/span>)\n\n<span class=\"hljs-comment\"># Upload with options<\/span>\nres = uploader.upload(\n\u00a0 \u00a0 <span class=\"hljs-string\">\"local-input.jpg\"<\/span>,\n\u00a0 \u00a0 folder=<span class=\"hljs-string\">\"qa-or-operator\"<\/span>,\n\u00a0 \u00a0 format=fmt,\n\u00a0 \u00a0 quality=quality\n)\n\n<span class=\"hljs-comment\"># Build a delivery URL with transformations<\/span>\nurl = CloudinaryImage(res&#91;<span class=\"hljs-string\">\"public_id\"<\/span>]).build_url(\n\u00a0 \u00a0 format=fmt,\n\u00a0 \u00a0 transformation=&#91;{<span class=\"hljs-string\">\"width\"<\/span>: <span class=\"hljs-number\">800<\/span>, <span class=\"hljs-string\">\"crop\"<\/span>: <span class=\"hljs-string\">\"scale\"<\/span>}]\n)\n<span class=\"hljs-keyword\">print<\/span>(url)<\/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<p class=\"wp-block-paragraph\">You can also explore a catalog of handy utilities for quick conversions and testing at <a href=\"https:\/\/cloudinary.com\/tools\">Cloudinary tools<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Summary<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>or<\/code> returns the first truthy operand, else the last one, and short-circuits.<\/li>\n\n\n\n<li>Be careful when 0 or empty values are valid inputs. Prefer explicit None checks.<\/li>\n\n\n\n<li>With arrays, use <code>|<\/code>, <code>any()<\/code>, or <code>all()<\/code> instead of <code>or<\/code>.<\/li>\n\n\n\n<li>Add parentheses to make precedence between <code>and<\/code> and <code>or<\/code> unambiguous.<\/li>\n\n\n\n<li>In real apps, or is great for fallbacks and defaults, including media workflows that later leverage Cloudinary for upload and delivery.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">TL;DR<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Python\u2019s <code>or<\/code> returns operands, not booleans. It short-circuits, so the right side may never run. Use it for lightweight defaults and fallbacks, but avoid it when <code>0<\/code> or empty values are valid. For arrays, prefer <code>|<\/code> or <code>any()<\/code>. In media pipelines, <code>or<\/code> helps set safe defaults before you upload or transform assets with services like Cloudinary.<\/p>\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\/png-to-webp\">PNG to WebP Converter<\/a><\/li>\n\n\n\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\/compress-webp\">Compress WebP<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudinary.com\/tools\/jpg-to-webp\">JPG to WebP<\/a><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Ready to streamline your media workflow with smart defaults and powerful delivery? <a href=\"https:\/\/cloudinary.com\/users\/register_free\">Sign up for Cloudinary<\/a> and start building today.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Python threads and dev chats, one of the most common logic questions pops up when writing config handling or fallbacks: why does this expression return a string instead of a boolean, and why did my function never run? That often traces back to Python\u2019s or operator and how it evaluates expressions. Question: I keep [&hellip;]<\/p>\n","protected":false},"author":88,"featured_media":39180,"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-39179","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 does the or operator work in Python?<\/title>\n<meta name=\"description\" content=\"In Python threads and dev chats, one of the most common logic questions pops up when writing config handling or fallbacks: why does this expression return\" \/>\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-does-the-or-operator-work-in-python\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How does the or operator work in Python?\" \/>\n<meta property=\"og:description\" content=\"In Python threads and dev chats, one of the most common logic questions pops up when writing config handling or fallbacks: why does this expression return\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-07T21:51:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-07T21:51:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762552253\/how_does_the_or_operator_work_in_python_featured_image\/how_does_the_or_operator_work_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-does-the-or-operator-work-in-python#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-does-the-or-operator-work-in-python\"},\"author\":{\"name\":\"damjanantevski\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#\\\/schema\\\/person\\\/43592e43c12520a1e867d456b1e8cf7e\"},\"headline\":\"How does the or operator work in Python?\",\"datePublished\":\"2025-11-07T21:51:14+00:00\",\"dateModified\":\"2025-11-07T21:51:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-does-the-or-operator-work-in-python\"},\"wordCount\":531,\"publisher\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-does-the-or-operator-work-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1762552253\\\/how_does_the_or_operator_work_in_python_featured_image\\\/how_does_the_or_operator_work_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-does-the-or-operator-work-in-python\",\"url\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-does-the-or-operator-work-in-python\",\"name\":\"How does the or operator work in Python?\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-does-the-or-operator-work-in-python#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-does-the-or-operator-work-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1762552253\\\/how_does_the_or_operator_work_in_python_featured_image\\\/how_does_the_or_operator_work_in_python_featured_image.jpg?_i=AA\",\"datePublished\":\"2025-11-07T21:51:14+00:00\",\"dateModified\":\"2025-11-07T21:51:15+00:00\",\"description\":\"In Python threads and dev chats, one of the most common logic questions pops up when writing config handling or fallbacks: why does this expression return\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-does-the-or-operator-work-in-python#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-does-the-or-operator-work-in-python\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-does-the-or-operator-work-in-python#primaryimage\",\"url\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1762552253\\\/how_does_the_or_operator_work_in_python_featured_image\\\/how_does_the_or_operator_work_in_python_featured_image.jpg?_i=AA\",\"contentUrl\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1762552253\\\/how_does_the_or_operator_work_in_python_featured_image\\\/how_does_the_or_operator_work_in_python_featured_image.jpg?_i=AA\",\"width\":2000,\"height\":1100},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/questions\\\/how-does-the-or-operator-work-in-python#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/cloudinary.com\\\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How does the or operator work 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 does the or operator work in Python?","description":"In Python threads and dev chats, one of the most common logic questions pops up when writing config handling or fallbacks: why does this expression return","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-does-the-or-operator-work-in-python","og_locale":"en_US","og_type":"article","og_title":"How does the or operator work in Python?","og_description":"In Python threads and dev chats, one of the most common logic questions pops up when writing config handling or fallbacks: why does this expression return","og_url":"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python","og_site_name":"Cloudinary Blog","article_published_time":"2025-11-07T21:51:14+00:00","article_modified_time":"2025-11-07T21:51:15+00:00","og_image":[{"width":2000,"height":1100,"url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762552253\/how_does_the_or_operator_work_in_python_featured_image\/how_does_the_or_operator_work_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-does-the-or-operator-work-in-python#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python"},"author":{"name":"damjanantevski","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/43592e43c12520a1e867d456b1e8cf7e"},"headline":"How does the or operator work in Python?","datePublished":"2025-11-07T21:51:14+00:00","dateModified":"2025-11-07T21:51:15+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python"},"wordCount":531,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762552253\/how_does_the_or_operator_work_in_python_featured_image\/how_does_the_or_operator_work_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-does-the-or-operator-work-in-python","url":"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python","name":"How does the or operator work in Python?","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762552253\/how_does_the_or_operator_work_in_python_featured_image\/how_does_the_or_operator_work_in_python_featured_image.jpg?_i=AA","datePublished":"2025-11-07T21:51:14+00:00","dateModified":"2025-11-07T21:51:15+00:00","description":"In Python threads and dev chats, one of the most common logic questions pops up when writing config handling or fallbacks: why does this expression return","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762552253\/how_does_the_or_operator_work_in_python_featured_image\/how_does_the_or_operator_work_in_python_featured_image.jpg?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762552253\/how_does_the_or_operator_work_in_python_featured_image\/how_does_the_or_operator_work_in_python_featured_image.jpg?_i=AA","width":2000,"height":1100},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog"},{"@type":"ListItem","position":2,"name":"How does the or operator work 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-does-the-or-operator-work-in-python","meta":{"@context":"https:\/\/schema.org","@type":"NewsArticle","headline":"How does the or operator work in Python?","url":"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python","mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-in-python"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762552253\/how_does_the_or_operator_work_in_python_featured_image\/how_does_the_or_operator_work_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\/v1762552253\/how_does_the_or_operator_work_in_python_featured_image\/how_does_the_or_operator_work_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-07T21:51:14Z","datePublished":"2025-11-07T21:51:14Z","dateModified":"2025-11-07T21:51:15Z"},"rendered":"<meta name=\"parsely-title\" content=\"How does the or operator work in Python?\" \/>\n<meta name=\"parsely-link\" content=\"https:\/\/cloudinary.com\/blog\/questions\/how-does-the-or-operator-work-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\/v1762552253\/how_does_the_or_operator_work_in_python_featured_image\/how_does_the_or_operator_work_in_python_featured_image.jpg?_i=AA&w=150&amp;h=150&amp;crop=1\" \/>\n<meta name=\"parsely-pub-date\" content=\"2025-11-07T21:51:14Z\" \/>\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\/v1762552253\/how_does_the_or_operator_work_in_python_featured_image\/how_does_the_or_operator_work_in_python_featured_image.jpg?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39179","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=39179"}],"version-history":[{"count":1,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39179\/revisions"}],"predecessor-version":[{"id":39181,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39179\/revisions\/39181"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/39180"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=39179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=39179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=39179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}