PYTHON LESSON 14 OF 32

Functions: your reusable recipes

Define a function with def. Parameters are names for the inputs. return sends a result back to the caller. Printing a value shows it; returning a value lets other code use it.

हिन्दी में समझें

def से फ़ंक्शन बनाएँ। पैरामीटर इनपुट के नाम हैं। return परिणाम वापस देता है। print केवल दिखाता है; return से दूसरा कोड परिणाम इस्तेमाल कर सकता है।

अभ्यास: double को 7 देकर 14 प्रिंट करें। फ़ंक्शन दोबारा उपयोग योग्य रखें।

Hinglish mein samjhein

def se function banao. Parameters inputs ke naam hain. return result wapas deta hai. print sirf dikhata hai; return ki value aage use hoti hai.

Practice: double(7) se 14 print karo. Function reusable rakho.

A small Python example

def double(number):
    return number * 2

print(double(6))

The browser playground runs real Python with Pyodide. Use sample variables instead of interactive input(). Browser package support differs from desktop Python.

Try this example in the Python playground →

Practise this idea

Call double with 7 and print 14. Keep the function reusable.

Check answer & explanation
def double(number):
    return number * 2

print(double(7))

The function multiplies its argument by 2. Calling it with 7 produces 14, while the same function still works for other inputs.

Stuck in the course? Choose Check answer for either the challenge or quiz. Read the explanation and continue to the next lesson at your own pace.

Check your understanding

What is returned by double(6)?

  1. 6
  2. 12
  3. None
Check the quiz answer

12

The function multiplies its input by 2.

References & corrections

Use the official Python documentation for full language rules. Read how these lessons are made and checked. Found a mistake? Report it to Excel Keys with this lesson URL and a reproducible example.

FROM LEARNING TO BUSINESS RESULTS

Need a dashboard for your team?

Excel Keys designs custom Excel and HTML dashboards around your own KPIs and Excel files. They run offline in the browser, so your data stays on your computer.