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

Python · Theory

def Function in Python

← All stacks

Theory

45/268

def Function in Python

def is the keyword that creates a named function. Shape: def total(a, b): return a + b. Colon, indented body. Optional docstring on the first line inside. Functions are objects — you can pass them to sorted(key=...) or store them. Without return, the caller gets None.

def vs lambda: def has a clear name and can have many lines. lambda is one expression. Freshers should live in def until the key= case appears.

def Function in Python — output — Hi Asha. def builds greet; the call runs it.

Diagram
def square(n):
      return n * n
         │ square(5)
         ▼
        25
Exam tip

def vs lambda: named reusable vs tiny expression.

Example

# def
def greet(name):
    return "Hi " + name

print(greet("Asha"))

def Function in Python — output: Hi Asha. def builds greet; the call runs it.

Short notes

  • Defdef creates a named function.
  • RuleIndented body + return.
  • Difflambda is tiny and unnamed.

Questions

1

Explain def Function 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 def Function?

Previous← Lambda Functions in PythonNextPython Modules →
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.