PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

Lambda Functions in Python

← All stacks

Theory

44/268

Lambda Functions in Python

lambda is a one-line function without a def name. Shape: lambda x: x * x. Useful as a key= in sorted, or a tiny map/filter. square = lambda n: n * n then square(5) is 25. Keep it tiny. If you need two statements, write a normal def. Complex lambda looks clever and reads badly.

Viva: “anonymous one-line function”. Then sorted(students, key=lambda s: s["marks"]). Prefer def when the logic has a name worth saying out loud.

Lambda Functions in Python — output — 5 then ['Asha', 'Neha', 'Ravi'] (or same lengths stay). add is a tiny function.

Diagram
lambda a, b: a + b
         │ (2, 3)
         ▼
         5
Exam tip

lambda with sorted key idea.

Example

# lambda
add = lambda a, b: a + b
print(add(2, 3))
print(sorted(["Neha", "Asha", "Ravi"], key=lambda s: len(s)))

Lambda Functions in Python — output: 5 then ['Asha', 'Neha', 'Ravi'] (or same lengths stay). add is a tiny function.

Short notes

  • DefTiny anonymous function.
  • RuleSingle expression.
  • Usekey= in sorted.

Questions

1

Explain Lambda Functions as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with Lambda Functions?

Previous← Python Built-in FunctionsNextdef Function in Python →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.