FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
in Python Programming by Goeduhub's Expert (9.3k points)
Describe Functions in Python
by (103 points)
learn about functions used in python

5 Answers

1 like 0 dislike
by Goeduhub's Expert (3.1k points)
edited by
Best answer

Python Function

  • Function is a group of statement that perform specific task.
  • Function help reduce line of code and break into small code section.
  •  basically function use  code in more organised and manageable.

In python there are three types of functions 

1.User defined function

2.Built in function 

3.Lambda Function

User defined function

User defined function made by user as their requirement. 

Defining a function

  • To define a function we use  def keyword with parenthesis.
  • We pass parameters/ arguments in parenthesis.
  • To close the function we use return(expression).

Syntax of a function

def function_Name( parameters ):
   return (expression)

#Calling a function 

Calling a function 

After defining a function we need to call a function to perform function task, In function calling we need to passed arguments in function.

Lets understand it with an example


#Defining a function 

def ADD (a,b):  

    return a+b;  

  #taking values from the user  

a = int(input("Enter a= "))  

b = int(input("Enter b= "))  

  #Calling a function

print("Sum = ",ADD(a,b))  


Enter a= 5 

Enter b=5 

Sum = 10


#defining a function

def Odd_Even( x ):

    if (x % 2 == 0): 

        print ("even")


        print ("odd")

#Calling a function






Parameters:-A variable listed inside a function when function is defined 

Arguments:-A variable is passed in a function during calling of function.

Different types of arguments in python function

Required arguments

Required arguments are the arguments passed to a function in correct positional order. Here, the number of arguments in the function call should match exactly with the function definition.


def add(a,b):






Note:-Here "a" and "b" are required argument without that you cannot perform or call a function , if you try without passing a and b it will give a syntax error.

Note:- In this type of argument variables arguments  taken by function are in correct positional order.

Keyword arguments

In this type of argument order of arguments does not matter,when we call function we define arguments with their respected values. It works like Key=value.


def Name_Age (Name,Age):




#Function calling





Default arguments

In Default argument it works ,when a argument value is not provided in function calling than it take a default value that is already defined in define function.

Note:-If a argument value is provided in function calling than  default value is avoided.


def Name_Age (Name,Age,salary=20000):





#Function calling


def Name_Age (Name,Age,salary=20000):





#Function calling



XYZ 21 


XYZ 21


Variable Length arguments

Sometimes we need more variables than already listed in function defining , in such cases we use variable length arguments.

An asterisk (*) is placed before the variable name that holds the values of all  variable arguments.


def Sum(*b):



    for i in b:





(1, 5, 6, 8)


Built-In Functions

  • A function that is built into an application and can be accessed by users is called built-in function. Python has a number of built-in functions.
  • For example-print() is a built-in function in python

 Some built-In python functions and their description

Function NameDescription
print()gives object on the screen or other standard output devices.
list()create a list
set()create a set 
len()shows the length of list, string etc
tuple()create a tuple 
type()shows type of a object  e,g-string, integer etc
max()shows maximum value from the given values 


#Sorting in ascending order 




#Descending order

Sort_L_Reverse =sorted(L, reverse=True)



[5, 7, 45, 54, 54, 65, 65, 462, 524, 546, 874, 6485] 

[6485, 874, 546, 524, 462, 65, 65, 54, 54, 45, 7, 5] 

Note:- If we want to sort a list without using built-in sorted function,for that we have to write a long code.Built-in functions make things easy to us.

Lambda Function

  • Lambda function is a anonymous function means that a function is without a name.
  • To create a small anonymous function lambda keyword is used.

Syntax of a lambda function

lambda arguments:expression


x = lambda a:a*n

n=int(input("A number="))   

print("sum = ",x(20)) 


A number=4 

sum = 80

Python Tutorial 

Machine Learning Tutorial 

AI Tutorial

Free Online Tutorials

by (101 points)
i read it completely
by (422 points)
Function is important topic and in this module function is explain briefly.
by (294 points)
Python function is also same as the other language like c,c,++,java
But in this lambda is the new term is introduced
by (100 points)
I Learned how to create function to perform a task. It makes simple and quicker code. We can use inbuilt functions or can create it by our own logics.
by (100 points)
In this article i learned about funtions. Functions are used for performing a specific task on it's calling that makes code readable and more efficient. Python have 3 types of funtions:-
1. Built-in functions
2. User defined functions
3. Lembda functions

User defined functions have argument that must be passed at the time of calling.
0 like 0 dislike
by Goeduhub's Expert (9.3k points)

Functions in Python

# Defining a function

def student_scores(English, German, Spanish, French):
   print ('My score in English is %d:' % English)
   print ('My score in German  is %d:' % German)
   print ('My score in Spanish is %d:' % Spanish)
   print ('My score in French  is %d:' % French)

# Scores given to function directly

print ('Scores given directly to student_scores function:')
student_scores(70, 83, 92, 73)

# Scores given to function using variables

print ('Scores given using variables:')
score_1 = 70
score_2 = 83
score_3 = 92
score_4 = 73
student_scores(score_1, score_2, score_3, score_4)

# Scores added and given to function

print ('Scores given by adding assignment scores:')
student_scores(65 + 5, 80 + 3, 90 + 2, 70 + 3)

# Scores added to varilable values and given to function 

print ('Scores added to values in variables')
student_scores(score_1 + 5, score_2 + 5, score_3 + 5, score_4 + 5)

0 like 0 dislike
by (391 points)
Date: 23/04/2020

Topic: Python Function

I Learned how to create function to perform a task. It makes simple and quicker code. We can use inbuilt functions or can create it by our own logics.
0 like 0 dislike
by (232 points)

                                                                                                 Topic-Python function

I learned about python function and their use in python. It makes simple and quicker code. We can use inbuilt functions or can create it by our own logics.

0 like 0 dislike
by (294 points)
In this module I learned the different type of functions used in python which is help in solve the complex problem

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

1 like 0 dislike
1 answer 383 views
1 like 0 dislike
6 answers 4.1k views
asked Oct 30, 2019 in Python Programming by Goeduhub Goeduhub's Expert (9.3k points)
0 like 0 dislike
1 answer 641 views
0 like 0 dislike
1 answer 409 views
0 like 0 dislike
1 answer 352 views

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs


About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © Social::   |  | 


Free Online Directory