{"id":39214,"date":"2025-11-08T09:08:38","date_gmt":"2025-11-08T17:08:38","guid":{"rendered":"https:\/\/cloudinary.com\/blog\/?p=39214"},"modified":"2025-11-08T09:08:39","modified_gmt":"2025-11-08T17:08:39","slug":"how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/","title":{"rendered":"How to skip an optional function argument using a ternary operator in Python?"},"content":{"rendered":"\n<p>You have a function with optional parameters and you want to pass one of them only when a condition is true. In many languages, it feels natural to try an inline conditional and move on. In Python, the details matter: passing <code>None<\/code> is not the same as skipping an argument entirely, and there is no syntax to \u201comit\u201d an argument from inside a single expression.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Question:<\/h2>\n\n\n\n<p><em>Hi all,<\/em><br><em>I have a function with optional keyword arguments, and I only want to pass one when a condition holds. I tried using a ternary at the call site but Python still expects a value. What is the correct pattern?<\/em><br><br><em>Concretely: How to skip an optional function argument using a ternary operator in Python? I want something concise that reads nicely in code reviews.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Answer:<\/h2>\n\n\n\n<p>Short answer: you cannot omit an argument from inside a single argument expression. Python evaluates the argument list before the function is called, so an inline expression must still produce a value. Long answer? Let\u2019s break it down.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1) Use a conditional expression across two separate calls<\/h3>\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\">def f(a, b=<span class=\"hljs-number\">10<\/span>):\n\u00a0 \u00a0 <span class=\"hljs-keyword\">return<\/span> a + b\n\ncond = <span class=\"hljs-keyword\">True<\/span>\nresult = f(<span class=\"hljs-number\">5<\/span>, b=<span class=\"hljs-number\">20<\/span>) <span class=\"hljs-keyword\">if<\/span> cond <span class=\"hljs-keyword\">else<\/span> f(<span class=\"hljs-number\">5<\/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>This keeps call sites explicit and works well for one or two options. It is also the most readable in many codebases.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2) Use kwargs unpacking to include a key only when needed<\/h3>\n\n\n\n<p>Build a small dictionary conditionally and unpack it with <code>**<\/code>. This lets you stay on one line while truly skipping the argument.<\/p>\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 f(a, b=<span class=\"hljs-number\">10<\/span>, c=<span class=\"hljs-number\">0<\/span>):\n\u00a0 \u00a0 <span class=\"hljs-keyword\">return<\/span> a + b + c\n\ncond_b = <span class=\"hljs-keyword\">True<\/span>\ncond_c = <span class=\"hljs-keyword\">False<\/span>\nresult = f(<span class=\"hljs-number\">5<\/span>, **({<span class=\"hljs-string\">'b'<\/span>: <span class=\"hljs-number\">20<\/span>} <span class=\"hljs-keyword\">if<\/span> cond_b <span class=\"hljs-keyword\">else<\/span> {}), **({<span class=\"hljs-string\">'c'<\/span>: <span class=\"hljs-number\">7<\/span>} <span class=\"hljs-keyword\">if<\/span> cond_c <span class=\"hljs-keyword\">else<\/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\">3) For multiple optionals, assemble a kwargs dict first<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">def f(a, b=<span class=\"hljs-number\">10<\/span>, c=<span class=\"hljs-number\">0<\/span>, d=None):\n\u00a0 \u00a0 ...\n\nkwargs = {}\n<span class=\"hljs-keyword\">if<\/span> use_b:\n\u00a0 \u00a0 kwargs&#91;<span class=\"hljs-string\">'b'<\/span>] = <span class=\"hljs-number\">20<\/span>\n<span class=\"hljs-keyword\">if<\/span> limit is not None:\n\u00a0 \u00a0 kwargs&#91;<span class=\"hljs-string\">'c'<\/span>] = limit\n<span class=\"hljs-keyword\">if<\/span> label:\n\u00a0 \u00a0 kwargs&#91;<span class=\"hljs-string\">'d'<\/span>] = label\n\nresult = f(<span class=\"hljs-number\">5<\/span>, **kwargs)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><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<p>This scales better and stays clean when several parameters are conditional.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4) If you control the function, use a sentinel default<\/h3>\n\n\n\n<p>Passing <code>None<\/code> is not the same as skipping. If you need to know whether the caller supplied a value, use a private sentinel.<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs shcb-wrap-lines\">SENTINEL = object()\n\ndef f(a, b=SENTINEL):\n\u00a0 \u00a0 if b is SENTINEL:\n\u00a0 \u00a0 \u00a0 \u00a0 b = compute_default()\n\u00a0 \u00a0 ...<\/code><\/span><\/pre>\n\n\n<p>Now callers can pass b=None as a legitimate value without being conflated with the default case.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Common pitfalls<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Trying <code>f(x, b=value if cond else None)<\/code> will pass <code>None<\/code>, not omit the argument.<\/li>\n\n\n\n<li>Using positional parameters makes it harder to skip just one in the middle. Prefer using keyword arguments instead.<\/li>\n\n\n\n<li>Side effects inside inline conditionals can hurt readability. Keep it simple.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Example with real code<\/h3>\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 read_image(path, color_mode=<span class=\"hljs-string\">\"rgb\"<\/span>, size=None, quality=None):\n\u00a0 \u00a0 <span class=\"hljs-comment\"># load image, maybe resize and re-encode<\/span>\n\u00a0 \u00a0 ...\n\n<span class=\"hljs-comment\"># 1) Two-call ternary<\/span>\nimg = read_image(<span class=\"hljs-string\">\"cat.jpg\"<\/span>, size=(<span class=\"hljs-number\">640<\/span>, <span class=\"hljs-number\">640<\/span>)) <span class=\"hljs-keyword\">if<\/span> need_resize <span class=\"hljs-keyword\">else<\/span> read_image(<span class=\"hljs-string\">\"cat.jpg\"<\/span>)\n\n<span class=\"hljs-comment\"># 2) Inline kwargs unpack<\/span>\nimg = read_image(<span class=\"hljs-string\">\"cat.jpg\"<\/span>, **({<span class=\"hljs-string\">'size'<\/span>: (<span class=\"hljs-number\">640<\/span>, <span class=\"hljs-number\">640<\/span>)} <span class=\"hljs-keyword\">if<\/span> need_resize <span class=\"hljs-keyword\">else<\/span> {}),\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 **({<span class=\"hljs-string\">'quality'<\/span>: <span class=\"hljs-number\">85<\/span>} <span class=\"hljs-keyword\">if<\/span> compress <span class=\"hljs-keyword\">else<\/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\">Using the same idea with Cloudinary<\/h3>\n\n\n\n<p>If you are uploading or transforming images in Python, you can apply the kwargs pattern with the Cloudinary Python SDK. For example, conditionally pass transformation options only when needed. This pairs nicely with workflows for <a href=\"https:\/\/cloudinary.com\/guides\/web-performance\/6-ways-to-save-images-in-python\">saving images in Python<\/a> and delivering optimized assets via an <a href=\"https:\/\/cloudinary.com\/glossary\/image-url\">image URL<\/a>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-keyword\">from<\/span> cloudinary.uploader <span class=\"hljs-keyword\">import<\/span> upload\n\nto_webp = True\ncap_quality = <span class=\"hljs-number\">80<\/span>\nfolder = <span class=\"hljs-string\">\"demos\"<\/span>\n\nopts = {<span class=\"hljs-string\">\"folder\"<\/span>: folder}\nopts |= {<span class=\"hljs-string\">\"format\"<\/span>: <span class=\"hljs-string\">\"webp\"<\/span>} <span class=\"hljs-keyword\">if<\/span> to_webp <span class=\"hljs-keyword\">else<\/span> {}\nopts |= {<span class=\"hljs-string\">\"quality\"<\/span>: cap_quality} <span class=\"hljs-keyword\">if<\/span> cap_quality is not None <span class=\"hljs-keyword\">else<\/span> {}\n\nres = upload(<span class=\"hljs-string\">\"cat.jpg\"<\/span>, **opts)\nprint(res&#91;<span class=\"hljs-string\">\"secure_url\"<\/span>])<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><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<p>Deciding whether to convert formats can also be informed by image goals.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">TL;DR<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You cannot omit an argument from within a single argument expression in Python.<\/li>\n\n\n\n<li>Use either a ternary that chooses between two full function calls or conditionally build <code>**kwargs<\/code>.<\/li>\n\n\n\n<li>For multiple options, assemble a dict and unpack it. For function internals, use a sentinel to distinguish \u201comitted\u201d from <code>None<\/code>.<\/li>\n\n\n\n<li>The same patterns work with SDKs like Cloudinary\u2019s to conditionally apply transformations and formats at upload time.<\/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\/webp-to-jpg\">WebP to JPG Converter<\/a><\/li>\n\n\n\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-upscale\">Image Upscale<\/a><\/li>\n<\/ul>\n\n\n\n<p>Ready to streamline your media pipeline with conditional parameters and on-the-fly transformations? <a href=\"https:\/\/cloudinary.com\/users\/register_free\">Create your free Cloudinary account<\/a> and start building.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You have a function with optional parameters and you want to pass one of them only when a condition is true. In many languages, it feels natural to try an inline conditional and move on. In Python, the details matter: passing None is not the same as skipping an argument entirely, and there is no [&hellip;]<\/p>\n","protected":false},"author":88,"featured_media":39215,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_cloudinary_featured_overwrite":false,"footnotes":""},"categories":[1],"tags":[423],"class_list":["post-39214","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 v25.6 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to skip an optional function argument using a ternary operator in Python?<\/title>\n<meta name=\"description\" content=\"You have a function with optional parameters and you want to pass one of them only when a condition is true. In many languages, it feels natural to try an\" \/>\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-skip-an-optional-function-argument-using-a-ternary-operator-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 skip an optional function argument using a ternary operator in Python?\" \/>\n<meta property=\"og:description\" content=\"You have a function with optional parameters and you want to pass one of them only when a condition is true. In many languages, it feels natural to try an\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-08T17:08:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-08T17:08:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762621700\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_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\":\"NewsArticle\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/\"},\"author\":{\"name\":\"damjanantevski\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/43592e43c12520a1e867d456b1e8cf7e\"},\"headline\":\"How to skip an optional function argument using a ternary operator in Python?\",\"datePublished\":\"2025-11-08T17:08:38+00:00\",\"dateModified\":\"2025-11-08T17:08:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/\"},\"wordCount\":516,\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762621700\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_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-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/\",\"url\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/\",\"name\":\"How to skip an optional function argument using a ternary operator in Python?\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762621700\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image.jpg?_i=AA\",\"datePublished\":\"2025-11-08T17:08:38+00:00\",\"dateModified\":\"2025-11-08T17:08:39+00:00\",\"description\":\"You have a function with optional parameters and you want to pass one of them only when a condition is true. In many languages, it feels natural to try an\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#primaryimage\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762621700\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image.jpg?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762621700\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image.jpg?_i=AA\",\"width\":2000,\"height\":1100},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudinary.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to skip an optional function argument using a ternary operator 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:\/\/cloudinary.com\/blog\/#\/schema\/person\/image\/\",\"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 skip an optional function argument using a ternary operator in Python?","description":"You have a function with optional parameters and you want to pass one of them only when a condition is true. In many languages, it feels natural to try an","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-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to skip an optional function argument using a ternary operator in Python?","og_description":"You have a function with optional parameters and you want to pass one of them only when a condition is true. In many languages, it feels natural to try an","og_url":"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/","og_site_name":"Cloudinary Blog","article_published_time":"2025-11-08T17:08:38+00:00","article_modified_time":"2025-11-08T17:08:39+00:00","og_image":[{"width":2000,"height":1100,"url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762621700\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image.jpg?_i=AA","type":"image\/jpeg"}],"author":"damjanantevski","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/"},"author":{"name":"damjanantevski","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/43592e43c12520a1e867d456b1e8cf7e"},"headline":"How to skip an optional function argument using a ternary operator in Python?","datePublished":"2025-11-08T17:08:38+00:00","dateModified":"2025-11-08T17:08:39+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/"},"wordCount":516,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762621700\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_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-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/","url":"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/","name":"How to skip an optional function argument using a ternary operator in Python?","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762621700\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image.jpg?_i=AA","datePublished":"2025-11-08T17:08:38+00:00","dateModified":"2025-11-08T17:08:39+00:00","description":"You have a function with optional parameters and you want to pass one of them only when a condition is true. In many languages, it feels natural to try an","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762621700\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image.jpg?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762621700\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image.jpg?_i=AA","width":2000,"height":1100},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/questions\/how-to-skip-an-optional-function-argument-using-a-ternary-operator-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to skip an optional function argument using a ternary operator 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:\/\/cloudinary.com\/blog\/#\/schema\/person\/image\/","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"}}]}},"jetpack_featured_media_url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1762621700\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image\/how_to_skip_an_optional_function_argument_using_a_ternary_operator_in_python_featured_image.jpg?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39214","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=39214"}],"version-history":[{"count":1,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39214\/revisions"}],"predecessor-version":[{"id":39216,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/39214\/revisions\/39216"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/39215"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=39214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=39214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=39214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}