{"id":66,"date":"2026-03-01T16:05:04","date_gmt":"2026-03-01T11:05:04","guid":{"rendered":"https:\/\/gigz.pk\/python\/?post_type=lesson&#038;p=66"},"modified":"2026-03-13T10:40:48","modified_gmt":"2026-03-13T05:40:48","slug":"lambda-functions","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/python\/lesson\/lambda-functions\/","title":{"rendered":"Lambda Functions"},"content":{"rendered":"\n<p>A <strong>lambda function<\/strong> is a small anonymous (unnamed) function in Python.<br>It is used for short, simple operations that can be written in a single line.<\/p>\n\n\n\n<p>Lambda functions are often used when a function is needed temporarily.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>SYNTAX OF LAMBDA FUNCTION<\/strong><\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">lambda arguments: expression<\/pre>\n\n\n\n<p>\u2022 <code>lambda<\/code> is the keyword<br>\u2022 Arguments are inputs (like parameters)<br>\u2022 Expression is the value that will be returned automatically<\/p>\n\n\n\n<p>Note: Lambda functions do not use the <code>return<\/code> keyword. The result of the expression is returned automatically.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>EXAMPLE 1: SIMPLE LAMBDA FUNCTION<\/strong><\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">add = lambda a, b: a + b<br>print(add(5, 3))<\/pre>\n\n\n\n<p>Output:<br>8<\/p>\n\n\n\n<p>This works similar to:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def add(a, b):<br>    return a + b<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>EXAMPLE 2: LAMBDA WITH ONE ARGUMENT<\/strong><\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">square = lambda x: x * x<br>print(square(4))<\/pre>\n\n\n\n<p>Output:<br>16<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>LAMBDA WITH IF-ELSE (CONDITIONAL EXPRESSION)<\/strong><\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">check_even = lambda x: \"Even\" if x % 2 == 0 else \"Odd\"<br>print(check_even(5))<\/pre>\n\n\n\n<p>Output:<br>Odd<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>USING LAMBDA WITH BUILT-IN FUNCTIONS<\/strong><\/h1>\n\n\n\n<p>Lambda functions are commonly used with functions like <code>map()<\/code>, <code>filter()<\/code>, and <code>sorted()<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example with map()<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers = [1, 2, 3, 4]<br>squares = list(map(lambda x: x * x, numbers))<br>print(squares)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Example with filter()<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">numbers = [1, 2, 3, 4, 5, 6]<br>evens = list(filter(lambda x: x % 2 == 0, numbers))<br>print(evens)<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>WHEN TO USE LAMBDA FUNCTIONS<\/strong><\/h1>\n\n\n\n<p>\u2022 For short, simple operations<br>\u2022 When passing a function as an argument<br>\u2022 When you need a quick temporary function<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>LIMITATIONS OF LAMBDA FUNCTIONS<\/strong><\/h1>\n\n\n\n<p>\u2022 Can only contain a single expression<br>\u2022 Cannot include multiple statements<br>\u2022 Less readable for complex logic<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>WHY LAMBDA FUNCTIONS ARE IMPORTANT<\/strong><\/h1>\n\n\n\n<p>\u2022 Make code shorter and cleaner<br>\u2022 Useful in functional programming<br>\u2022 Help write concise and efficient programs<\/p>\n\n\n\n<p>Understanding <strong>lambda functions<\/strong> helps you write compact and professional Python code.<\/p>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773380483545\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/python\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">PYTHON FUNDAMENTALS (PYF) > Functions > Lambda Functions<\/span><\/span><\/div>\n\n\n<p><\/p>\n","protected":false},"menu_order":24,"template":"","class_list":["post-66","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Lambda Functions - One Language. Endless Possibilities<\/title>\n<meta name=\"description\" content=\"Learn Python lambda functions: create anonymous, single-line functions, use with map\/filter, and write concise, efficient code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/python\/lesson\/lambda-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Lambda Functions - One Language. Endless Possibilities\" \/>\n<meta property=\"og:description\" content=\"Learn Python lambda functions: create anonymous, single-line functions, use with map\/filter, and write concise, efficient code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/python\/lesson\/lambda-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"One Language. Endless Possibilities\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-13T05:40:48+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/lambda-functions\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/lambda-functions\\\/\",\"name\":\"Lambda Functions - One Language. Endless Possibilities\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\"},\"datePublished\":\"2026-03-01T11:05:04+00:00\",\"dateModified\":\"2026-03-13T05:40:48+00:00\",\"description\":\"Learn Python lambda functions: create anonymous, single-line functions, use with map\\\/filter, and write concise, efficient code.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/lambda-functions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/lambda-functions\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/lambda-functions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PYTHON FUNDAMENTALS (PYF) > Functions > Lambda Functions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\",\"name\":\"One Language. Endless Possibilities\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/python\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Lambda Functions - One Language. Endless Possibilities","description":"Learn Python lambda functions: create anonymous, single-line functions, use with map\/filter, and write concise, efficient code.","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:\/\/gigz.pk\/python\/lesson\/lambda-functions\/","og_locale":"en_US","og_type":"article","og_title":"Lambda Functions - One Language. Endless Possibilities","og_description":"Learn Python lambda functions: create anonymous, single-line functions, use with map\/filter, and write concise, efficient code.","og_url":"https:\/\/gigz.pk\/python\/lesson\/lambda-functions\/","og_site_name":"One Language. Endless Possibilities","article_modified_time":"2026-03-13T05:40:48+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/python\/lesson\/lambda-functions\/","url":"https:\/\/gigz.pk\/python\/lesson\/lambda-functions\/","name":"Lambda Functions - One Language. Endless Possibilities","isPartOf":{"@id":"https:\/\/gigz.pk\/python\/#website"},"datePublished":"2026-03-01T11:05:04+00:00","dateModified":"2026-03-13T05:40:48+00:00","description":"Learn Python lambda functions: create anonymous, single-line functions, use with map\/filter, and write concise, efficient code.","breadcrumb":{"@id":"https:\/\/gigz.pk\/python\/lesson\/lambda-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/python\/lesson\/lambda-functions\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/python\/lesson\/lambda-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/python\/"},{"@type":"ListItem","position":2,"name":"PYTHON FUNDAMENTALS (PYF) > Functions > Lambda Functions"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/python\/#website","url":"https:\/\/gigz.pk\/python\/","name":"One Language. Endless Possibilities","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson\/66","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/media?parent=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}