B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP User Defined Functions with Parameters in Python | LiveCodeProgramming
Python Installation First Python Program Control Flow if...else nested if else match-case logical-operators for loops while loops break / continue Functions Defining Functions Function Arguments Function return value Lambda Function Recursion Exception Handling Exception Handling Try Except Else and Finally Raise Exception Custom Exceptions File Handling File in python Read File Write File Append File Delete File Exception Handling

Python Function with Parameters

Functions with parameters allow you to pass values when calling the function. These values are used inside the function to perform tasks.

Parameters वाली function में आप values को function को call करते समय भेज सकते हैं। ये values function के अंदर इस्तेमाल होती हैं।

  1. Greet a person
    def greet(name):
        print("Hello,", name)
    
    greet("Ankit")
    Output:
    Hello, Ankit
  2. Add two numbers
    def add(a, b):
        print("Sum:", a + b)
    
    add(3, 7)
    Output:
    Sum: 10
  3. Check eligibility for voting
    def check_vote(age):
        if age >= 18:
            print("Eligible to vote")
        else:
            print("Not eligible")
    
    check_vote(20)
    Output:
    Eligible to vote
  4. Print multiplication table
    def table(n):
        for i in range(1, 11):
            print(n, "x", i, "=", n*i)
    
    table(6)
    Output:
    6 x 1 = 6
    ...
    6 x 10 = 60
  5. Check even or odd
    def even_odd(n):
        if n % 2 == 0:
            print("Even")
        else:
            print("Odd")
    
    even_odd(13)
    Output:
    Odd
  6. Area of rectangle
    def area(length, width):
        print("Area:", length * width)
    
    area(5, 4)
    Output:
    Area: 20
  7. Find maximum of 3 numbers
    def maximum(a, b, c):
        print("Max:", max(a, b, c))
    
    maximum(5, 12, 9)
    Output:
    Max: 12
  8. Calculate simple interest
    def interest(p, r, t):
        si = (p * r * t) / 100
        print("Simple Interest:", si)
    
    interest(1000, 5, 2)
    Output:
    Simple Interest: 100.0
  9. Display student info
    def student(name, roll):
        print("Name:", name)
        print("Roll No:", roll)
    
    student("Ravi", 101)
    Output:
    Name: Ravi
    Roll No: 101
  10. Print stars line
    def stars(n):
        print("*" * n)
    
    stars(8)
    Output:
    ********