Skip to content

Language

Sign in

Learn › Class 12 › Computer Science / Informatics Practices › Python revision, functions, exceptions

Functions in Python

Example 1: A function with a default parameter

Open one step at a time. Try the next step yourself first.

  1. Step 1. def power(x, n=2): return x ** n
  2. Show step 2

    power(3) uses n = 2 and returns 9.

  3. Show step 3

    power(2, n=5) returns 2 ** 5 = 32.

Example 2: Local and global x

Open one step at a time. Try the next step yourself first.

  1. Step 1. x = 5 at the top level.
  2. Show step 2

    def f(): x = 10 creates a new local x inside f.

  3. Show step 3

    After calling f(), print(x) still shows 5, because the global x was never changed.

Reviewed by EduFlint team on 1 Dec 2026 · version 1

Written by us for this site. Independent; not affiliated with NCERT or CBSE.

Report a mistake

Looking for another topic?

Functions in Python: Class 12 Computer Science / Informatics Practices · EduFlint