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

Python · Theory

Functions in Python

← All stacks

Theory

42/268

Functions in Python

A function is a reusable block that does one job. You write it once with def, then call it. square(5) should return 25 — not only print it, if the caller needs the number.

Shape: def square(n): return n * n. Colon, indented body. Call: print(square(5)). Output 25. Without return, the function gives None. Freshers print inside and wonder why x = square(5) is None.

Defaults: def greet(name="Guest"). Call greet() or greet("Asha"). Keep one job per function. Name it after what it does: total_marks, not do_stuff.

Let’s do it on the board. def square(n): return n * n. print(square(5)) → 25. Change to square(6) in your head → 36. That dry-run is the example.

Functions in Python — output — 25. square(5) returns 25. Change to square(6) → 36.

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

Explain return vs no return.

Example

# Functions
def square(n):
    return n * n

print(square(5))

Functions in Python — output: 25. square(5) returns 25. Change to square(6) → 36.

Short notes

  • DefA function is a reusable block that does one job.
  • RuleShape: def square(n): return n * n.
  • RememberDefaults: def greet(name="Guest").

Questions

1

Explain 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 Functions?

Previous← Set vs Dictionary in PythonNextPython Built-in Functions →
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.