SlideShare a Scribd company logo
2
A function is a block of organized, reusable code that is used to perform
a single, related action.
What are Functions?
Functions are a convenient way to divide your code into useful blocks,
allowing us to order our code, make it more readable, reuse it and save
some time. Also functions are a key way to define interfaces so
programmers can share their code.
A Function in Python is used to utilize the code in more than one place
in a program. It is also called method or procedures.
Most read
15
We discuss one module file:
Inside this Math module there are many functions of math's
ceil()
floor()
pow(x,y) sqrt(value)
cos(value)sin(value) tan(value)
Which includes trigonometric functions, representation functions,
logarithmic functions, etc.
Math.py
Math.pi
Most read
16
ceil()
floor() It rounds a number downwards to its nearest integer
It rounds a number upwards to its nearest integer.
import math
x = math.ceil(1.4)
print(x)
-----OUTPUT-----
2
import math
x = math.floor(1.4)
print(x)
-----OUTPUT-----
1
import math
x = math.ceil(-1.4)
print(x)
-----OUTPUT-----
-1
import math
x = math.floor(-1.4)
print(x)
-----OUTPUT-----
-2
Most read
FUNCTIONS IN PYTHON
CLASS: XII
COMPUTER SCIENCE(083)
INTRODUCTION
A function is a block of organized, reusable code that is used to perform
a single, related action.
What are Functions?
Functions are a convenient way to divide your code into useful blocks,
allowing us to order our code, make it more readable, reuse it and save
some time. Also functions are a key way to define interfaces so
programmers can share their code.
A Function in Python is used to utilize the code in more than one place
in a program. It is also called method or procedures.
Why we need functions?
We can easily work with problems whose solutions can be written in the
form of small python programs.
Like Example: To Accept the name and display it.
nm=input(“enter the name”)
print(“your name=“,nm)
As the problems become more complex, then the program size and
complexity and it become very difficult for you to keep track of the data
and know each and every line.
So python provides the feature to divide a large program into different smaller
modules or functions. These have the responsibility to work upon data for
processing. Example:
statements
statements
statements
statements
statements
statements
statements
statements
statements
.
.
.
statements
This
program is
one long,
complex
sequences
of
statements
If we are using
the functions
the task divided
into smaller
tasks, each task
perform his
work and all
these task are
combined when
need according
to requirements
Function1:
statements
statements
statements
statements
Function2:
statements
statements
statements
statements
Function3:
statements
statements
statements
statements
Task 1:
Task 2:
Task 3:
TYPES OF FUNCTIONS
There are three types of functions categories:
Built-in functions:
Modules:
User define Functions:
Built-In Functions
The Python built-in functions are predefined functions that are already
available in python. It makes programming more easier, faster and more
powerful. These are always available in the standard library.
Type conversion functions:
It provide functions that convert values from one type to another.
str() :
float() :
eval() :
int() :
int() : Convert any value into an integer.
Example:
If we want to accept two numbers A, B from user and using input() and
you know that input return string, so we need to convert it to number
using int()
A=int(input(“Enter value for A”))
B=int(input(“Enter value for B”))
s=A+B
print(“sum=“,s)
--------OUTPUT---------
Enter value of A 20
Enter value of B 30
sum=50
A=input(“Enter value for A”)
B=input(“Enter value for B”)
s=A+B
print(“sum=“,s)
--------OUTPUT---------
Enter value of A 20
Enter value of B 30
sum=2030
It concatenate means
joining of characters
str() : Convert any value into an string.
Example:
If we want to convert number 25 into a string, so we need to use str()
A=25
print(“A=“,A)
--------OUTPUT---------
A=25
A=25
print(“A=“,str(A))
--------OUTPUT---------
A=’25’
float() : Convert any value into an string.
Example:
If we want to convert number 25 into a floating value, so we need to use
float()
A=float(25)
print(“A=“,A)
--------OUTPUT---------
A=25.0
If we convert a string value into
float
A=float(‘45.895’)
print(“A=“,A)
--------OUTPUT---------
A=45.895
eval() : It is used to evaluate the value of string. It takes value as string
and evaluates it into integer or float
A=eval(‘45+10’)
print(“A=“,A)
--------OUTPUT---------
A=55
If we accept value in integer or float it
should automatically evaluate by the
function for that we use eval().
A=eval(input(“enter the value”))
print(“A=“,A)
If we enter value in number it convert
it automatically into number
--------OUTPUT---------
Enter the value 45
A=45
If we enter value in number it convert
it automatically into number
--------OUTPUT---------
Enter the value 45.78
A=45.78
abs() : It return absolute value of a single number. It takes an integer or
floating value and always return positive value.
A=abs(-45)
print(“A=“,A)
--------OUTPUT---------
A=45
A=abs(-45.85)
print(“A=“,A)
--------OUTPUT---------
A=45.85
pow(x,y) : function returns the value of x to the power of y (xy)
A=pow(2,3)
print(“A=“,A)
--------OUTPUT---------
A=8
type() : If you wish to find the type of a variable,
A=10
B=9.23
C=‘That’
N=[1,2,3]
M=(20,30)
D={‘rollno’:101,’name’:’rohit’}
print(type(A))
print(type(B))
print(type(C))
print(type(N))
print(type(M))
print(type(D))
-------OUTPUT----------
<class 'int'>
<class 'float'>
<class 'str'>
<class 'list'>
<class 'tuple'>
<class 'dict'>
round() : It is used to get the result up to a specified number of digits.
print(round(10))
print(round(10.8))
print(round(6.3))
-----Output-----
10
11
6
The round() method takes two argument
• The number to be rounded and
• Up to how many decimal places
If the number after the decimal place given
• >=5 than + 1 will be added to the final value
• <5 than the final value will return as it is
print(round(10.535,0))
print(round(10.535,1))
pprint(round(10.535,2))
-----Output-----
11.0
10.5
10.54
Modules
A file containing functions and variables defined in separate files. A
module is simply a file that contain python code in the form of separate
functions with special task. The module file extension is same .py . To use
it, you must import the math module:
We discuss one module file:
Inside this Math module there are many functions of math's
ceil()
floor()
pow(x,y) sqrt(value)
cos(value)sin(value) tan(value)
Which includes trigonometric functions, representation functions,
logarithmic functions, etc.
Math.py
Math.pi
ceil()
floor() It rounds a number downwards to its nearest integer
It rounds a number upwards to its nearest integer.
import math
x = math.ceil(1.4)
print(x)
-----OUTPUT-----
2
import math
x = math.floor(1.4)
print(x)
-----OUTPUT-----
1
import math
x = math.ceil(-1.4)
print(x)
-----OUTPUT-----
-1
import math
x = math.floor(-1.4)
print(x)
-----OUTPUT-----
-2
pow(x,y)
This method returns the power of the x corresponding to the
value of y. In other words, pow(2,4) is equivalent to 2**4.
import math
number = math.pow(2,4)
print("The power of number:",number)
-------OUTPUT------
The power of number: 16
number = 2**4
print("The power of number:",number)
-------OUTPUT------
The power of number: 16
sqrt(value) It returns the square root of a given number.
import math
print(math.sqrt(100))
----OUTPUT----
10.0
import math
print(math.sqrt(3))
----OUTPUT----
1.7320508075688772
Math.pi
It is a well-known mathematical constant and defined as the ratio of
circumstance to the diameter of a circle. Its value is 3.141592653589793.
import math
print(math.pi)
------OUTPUT------
3.141592653589793
cos(value)sin(value) tan(value)
Trigonometric functions
This function
returns the sine of
value passed as
argument. The
value passed in this
function should be
in radians.
This function returns
the cosine of value
passed as argument.
The value passed in
this function should
be in radians.
This function returns the
tangent of value passed as
argument. The value
passed in this function
should be in radians.

More Related Content

What's hot (20)

Dictionaries in Python
Dictionaries in PythonDictionaries in Python
Dictionaries in Python
baabtra.com - No. 1 supplier of quality freshers
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
Dipankar Achinta
 
Python Programming Essentials - M24 - math module
Python Programming Essentials - M24 - math modulePython Programming Essentials - M24 - math module
Python Programming Essentials - M24 - math module
P3 InfoTech Solutions Pvt. Ltd.
 
Python programming
Python  programmingPython  programming
Python programming
Ashwin Kumar Ramasamy
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
Sujith Kumar
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
Emertxe Information Technologies Pvt Ltd
 
for loop in java
for loop in java for loop in java
for loop in java
Majid Ali
 
List in Python
List in PythonList in Python
List in Python
Sharath Ankrajegowda
 
Python basics
Python basicsPython basics
Python basics
Hoang Nguyen
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
•sreejith •sree
 
Array data structure
Array data structureArray data structure
Array data structure
maamir farooq
 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in Python
Sumit Satam
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
Tahani Al-Manie
 
Python tuple
Python   tuplePython   tuple
Python tuple
Mohammed Sikander
 
Python
PythonPython
Python
Aashish Jain
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
narmadhakin
 
C Token’s
C Token’sC Token’s
C Token’s
Tarun Sharma
 

Similar to INTRODUCTION TO FUNCTIONS IN PYTHON (20)

PYTHON-PROGRAMMING-UNIT-II (1).pptx
PYTHON-PROGRAMMING-UNIT-II (1).pptxPYTHON-PROGRAMMING-UNIT-II (1).pptx
PYTHON-PROGRAMMING-UNIT-II (1).pptx
georgejustymirobi1
 
PYTHON-PROGRAMMING-UNIT-II.pptx gijtgjjgg jufgiju yrguhft hfgjutt jgg
PYTHON-PROGRAMMING-UNIT-II.pptx gijtgjjgg jufgiju yrguhft hfgjutt jggPYTHON-PROGRAMMING-UNIT-II.pptx gijtgjjgg jufgiju yrguhft hfgjutt jgg
PYTHON-PROGRAMMING-UNIT-II.pptx gijtgjjgg jufgiju yrguhft hfgjutt jgg
DeepakRattan3
 
Functions.docx
Functions.docxFunctions.docx
Functions.docx
VandanaGoyal21
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Ch no 4 Python Functions,Modules & packages.pptx
Ch no 4 Python Functions,Modules & packages.pptxCh no 4 Python Functions,Modules & packages.pptx
Ch no 4 Python Functions,Modules & packages.pptx
gboy4529248
 
Python Lecture 4
Python Lecture 4Python Lecture 4
Python Lecture 4
Inzamam Baig
 
function_xii-BY APARNA DENDRE (1).pdf.pptx
function_xii-BY APARNA DENDRE (1).pdf.pptxfunction_xii-BY APARNA DENDRE (1).pdf.pptx
function_xii-BY APARNA DENDRE (1).pdf.pptx
g84017903
 
Python programming unit 2 -Slides-3.ppt
Python programming  unit 2 -Slides-3.pptPython programming  unit 2 -Slides-3.ppt
Python programming unit 2 -Slides-3.ppt
geethar79
 
Dive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdfDive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdf
SudhanshiBakre1
 
Functions-.pdf
Functions-.pdfFunctions-.pdf
Functions-.pdf
arvdexamsection
 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.ppt
jaba kumar
 
introduction to python programming course 2
introduction to python programming course 2introduction to python programming course 2
introduction to python programming course 2
FarhadMohammadRezaHa
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
VijaySharma802
 
Python Objects
Python ObjectsPython Objects
Python Objects
MuhammadBakri13
 
Chapter Functions for grade 12 computer Science
Chapter Functions for grade 12 computer ScienceChapter Functions for grade 12 computer Science
Chapter Functions for grade 12 computer Science
KrithikaTM
 
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptx
SahajShrimal1
 
Introduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIMLIntroduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIML
VijaySharma802
 
Python Modules and Libraries
Python Modules and LibrariesPython Modules and Libraries
Python Modules and Libraries
Venugopalavarma Raja
 
Python Modules, Packages and Libraries
Python Modules, Packages and LibrariesPython Modules, Packages and Libraries
Python Modules, Packages and Libraries
Venugopalavarma Raja
 
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
UadAccount
 
PYTHON-PROGRAMMING-UNIT-II (1).pptx
PYTHON-PROGRAMMING-UNIT-II (1).pptxPYTHON-PROGRAMMING-UNIT-II (1).pptx
PYTHON-PROGRAMMING-UNIT-II (1).pptx
georgejustymirobi1
 
PYTHON-PROGRAMMING-UNIT-II.pptx gijtgjjgg jufgiju yrguhft hfgjutt jgg
PYTHON-PROGRAMMING-UNIT-II.pptx gijtgjjgg jufgiju yrguhft hfgjutt jggPYTHON-PROGRAMMING-UNIT-II.pptx gijtgjjgg jufgiju yrguhft hfgjutt jgg
PYTHON-PROGRAMMING-UNIT-II.pptx gijtgjjgg jufgiju yrguhft hfgjutt jgg
DeepakRattan3
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Ch no 4 Python Functions,Modules & packages.pptx
Ch no 4 Python Functions,Modules & packages.pptxCh no 4 Python Functions,Modules & packages.pptx
Ch no 4 Python Functions,Modules & packages.pptx
gboy4529248
 
function_xii-BY APARNA DENDRE (1).pdf.pptx
function_xii-BY APARNA DENDRE (1).pdf.pptxfunction_xii-BY APARNA DENDRE (1).pdf.pptx
function_xii-BY APARNA DENDRE (1).pdf.pptx
g84017903
 
Python programming unit 2 -Slides-3.ppt
Python programming  unit 2 -Slides-3.pptPython programming  unit 2 -Slides-3.ppt
Python programming unit 2 -Slides-3.ppt
geethar79
 
Dive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdfDive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdf
SudhanshiBakre1
 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.ppt
jaba kumar
 
introduction to python programming course 2
introduction to python programming course 2introduction to python programming course 2
introduction to python programming course 2
FarhadMohammadRezaHa
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
VijaySharma802
 
Chapter Functions for grade 12 computer Science
Chapter Functions for grade 12 computer ScienceChapter Functions for grade 12 computer Science
Chapter Functions for grade 12 computer Science
KrithikaTM
 
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptx
SahajShrimal1
 
Introduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIMLIntroduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIML
VijaySharma802
 
Python Modules, Packages and Libraries
Python Modules, Packages and LibrariesPython Modules, Packages and Libraries
Python Modules, Packages and Libraries
Venugopalavarma Raja
 
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
UadAccount
 
Ad

More from vikram mahendra (20)

Communication skill
Communication skillCommunication skill
Communication skill
vikram mahendra
 
Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop system
vikram mahendra
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shop
vikram mahendra
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEM
vikram mahendra
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Python
vikram mahendra
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
vikram mahendra
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHON
vikram mahendra
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
vikram mahendra
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
vikram mahendra
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
vikram mahendra
 
DATA TYPE IN PYTHON
DATA TYPE IN PYTHONDATA TYPE IN PYTHON
DATA TYPE IN PYTHON
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
vikram mahendra
 
GREEN SKILL[PART-2]
GREEN SKILL[PART-2]GREEN SKILL[PART-2]
GREEN SKILL[PART-2]
vikram mahendra
 
GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]
vikram mahendra
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
vikram mahendra
 
Entrepreneurial skills
Entrepreneurial skillsEntrepreneurial skills
Entrepreneurial skills
vikram mahendra
 
Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop system
vikram mahendra
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shop
vikram mahendra
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEM
vikram mahendra
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Python
vikram mahendra
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
vikram mahendra
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHON
vikram mahendra
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
vikram mahendra
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
vikram mahendra
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 
Ad

Recently uploaded (20)

Swachata Quiz - Prelims - 01.10.24 - Quiz Club IIT Patna
Swachata Quiz - Prelims - 01.10.24 - Quiz Club IIT PatnaSwachata Quiz - Prelims - 01.10.24 - Quiz Club IIT Patna
Swachata Quiz - Prelims - 01.10.24 - Quiz Club IIT Patna
Quiz Club, Indian Institute of Technology, Patna
 
Exploring Identity Through Colombian Companies
Exploring Identity Through Colombian CompaniesExploring Identity Through Colombian Companies
Exploring Identity Through Colombian Companies
OlgaLeonorTorresSnch
 
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptxQUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
Sourav Kr Podder
 
Writing Research Papers: Guidance for Research Community
Writing Research Papers: Guidance for Research CommunityWriting Research Papers: Guidance for Research Community
Writing Research Papers: Guidance for Research Community
Rishi Bankim Chandra Evening College, Naihati, North 24 Parganas, West Bengal, India
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ..."Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
Arshad Shaikh
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
How to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 WebsiteHow to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 Website
Celine George
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly WorkshopsLDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDM & Mia eStudios
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
Arshad Shaikh
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
LDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College VolumeLDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College Volume
LDM & Mia eStudios
 
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSELET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
OlgaLeonorTorresSnch
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 
Exploring Identity Through Colombian Companies
Exploring Identity Through Colombian CompaniesExploring Identity Through Colombian Companies
Exploring Identity Through Colombian Companies
OlgaLeonorTorresSnch
 
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptxQUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
Sourav Kr Podder
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ..."Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
Arshad Shaikh
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
How to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 WebsiteHow to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 Website
Celine George
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly WorkshopsLDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDM & Mia eStudios
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
Arshad Shaikh
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
LDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College VolumeLDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College Volume
LDM & Mia eStudios
 
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSELET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
OlgaLeonorTorresSnch
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 

INTRODUCTION TO FUNCTIONS IN PYTHON

  • 1. FUNCTIONS IN PYTHON CLASS: XII COMPUTER SCIENCE(083) INTRODUCTION
  • 2. A function is a block of organized, reusable code that is used to perform a single, related action. What are Functions? Functions are a convenient way to divide your code into useful blocks, allowing us to order our code, make it more readable, reuse it and save some time. Also functions are a key way to define interfaces so programmers can share their code. A Function in Python is used to utilize the code in more than one place in a program. It is also called method or procedures.
  • 3. Why we need functions? We can easily work with problems whose solutions can be written in the form of small python programs. Like Example: To Accept the name and display it. nm=input(“enter the name”) print(“your name=“,nm) As the problems become more complex, then the program size and complexity and it become very difficult for you to keep track of the data and know each and every line.
  • 4. So python provides the feature to divide a large program into different smaller modules or functions. These have the responsibility to work upon data for processing. Example: statements statements statements statements statements statements statements statements statements . . . statements This program is one long, complex sequences of statements If we are using the functions the task divided into smaller tasks, each task perform his work and all these task are combined when need according to requirements Function1: statements statements statements statements Function2: statements statements statements statements Function3: statements statements statements statements Task 1: Task 2: Task 3:
  • 5. TYPES OF FUNCTIONS There are three types of functions categories: Built-in functions: Modules: User define Functions:
  • 6. Built-In Functions The Python built-in functions are predefined functions that are already available in python. It makes programming more easier, faster and more powerful. These are always available in the standard library. Type conversion functions: It provide functions that convert values from one type to another. str() : float() : eval() : int() :
  • 7. int() : Convert any value into an integer. Example: If we want to accept two numbers A, B from user and using input() and you know that input return string, so we need to convert it to number using int() A=int(input(“Enter value for A”)) B=int(input(“Enter value for B”)) s=A+B print(“sum=“,s) --------OUTPUT--------- Enter value of A 20 Enter value of B 30 sum=50 A=input(“Enter value for A”) B=input(“Enter value for B”) s=A+B print(“sum=“,s) --------OUTPUT--------- Enter value of A 20 Enter value of B 30 sum=2030 It concatenate means joining of characters
  • 8. str() : Convert any value into an string. Example: If we want to convert number 25 into a string, so we need to use str() A=25 print(“A=“,A) --------OUTPUT--------- A=25 A=25 print(“A=“,str(A)) --------OUTPUT--------- A=’25’
  • 9. float() : Convert any value into an string. Example: If we want to convert number 25 into a floating value, so we need to use float() A=float(25) print(“A=“,A) --------OUTPUT--------- A=25.0 If we convert a string value into float A=float(‘45.895’) print(“A=“,A) --------OUTPUT--------- A=45.895
  • 10. eval() : It is used to evaluate the value of string. It takes value as string and evaluates it into integer or float A=eval(‘45+10’) print(“A=“,A) --------OUTPUT--------- A=55 If we accept value in integer or float it should automatically evaluate by the function for that we use eval(). A=eval(input(“enter the value”)) print(“A=“,A) If we enter value in number it convert it automatically into number --------OUTPUT--------- Enter the value 45 A=45 If we enter value in number it convert it automatically into number --------OUTPUT--------- Enter the value 45.78 A=45.78
  • 11. abs() : It return absolute value of a single number. It takes an integer or floating value and always return positive value. A=abs(-45) print(“A=“,A) --------OUTPUT--------- A=45 A=abs(-45.85) print(“A=“,A) --------OUTPUT--------- A=45.85 pow(x,y) : function returns the value of x to the power of y (xy) A=pow(2,3) print(“A=“,A) --------OUTPUT--------- A=8
  • 12. type() : If you wish to find the type of a variable, A=10 B=9.23 C=‘That’ N=[1,2,3] M=(20,30) D={‘rollno’:101,’name’:’rohit’} print(type(A)) print(type(B)) print(type(C)) print(type(N)) print(type(M)) print(type(D)) -------OUTPUT---------- <class 'int'> <class 'float'> <class 'str'> <class 'list'> <class 'tuple'> <class 'dict'>
  • 13. round() : It is used to get the result up to a specified number of digits. print(round(10)) print(round(10.8)) print(round(6.3)) -----Output----- 10 11 6 The round() method takes two argument • The number to be rounded and • Up to how many decimal places If the number after the decimal place given • >=5 than + 1 will be added to the final value • <5 than the final value will return as it is print(round(10.535,0)) print(round(10.535,1)) pprint(round(10.535,2)) -----Output----- 11.0 10.5 10.54
  • 14. Modules A file containing functions and variables defined in separate files. A module is simply a file that contain python code in the form of separate functions with special task. The module file extension is same .py . To use it, you must import the math module:
  • 15. We discuss one module file: Inside this Math module there are many functions of math's ceil() floor() pow(x,y) sqrt(value) cos(value)sin(value) tan(value) Which includes trigonometric functions, representation functions, logarithmic functions, etc. Math.py Math.pi
  • 16. ceil() floor() It rounds a number downwards to its nearest integer It rounds a number upwards to its nearest integer. import math x = math.ceil(1.4) print(x) -----OUTPUT----- 2 import math x = math.floor(1.4) print(x) -----OUTPUT----- 1 import math x = math.ceil(-1.4) print(x) -----OUTPUT----- -1 import math x = math.floor(-1.4) print(x) -----OUTPUT----- -2
  • 17. pow(x,y) This method returns the power of the x corresponding to the value of y. In other words, pow(2,4) is equivalent to 2**4. import math number = math.pow(2,4) print("The power of number:",number) -------OUTPUT------ The power of number: 16 number = 2**4 print("The power of number:",number) -------OUTPUT------ The power of number: 16
  • 18. sqrt(value) It returns the square root of a given number. import math print(math.sqrt(100)) ----OUTPUT---- 10.0 import math print(math.sqrt(3)) ----OUTPUT---- 1.7320508075688772 Math.pi It is a well-known mathematical constant and defined as the ratio of circumstance to the diameter of a circle. Its value is 3.141592653589793. import math print(math.pi) ------OUTPUT------ 3.141592653589793
  • 19. cos(value)sin(value) tan(value) Trigonometric functions This function returns the sine of value passed as argument. The value passed in this function should be in radians. This function returns the cosine of value passed as argument. The value passed in this function should be in radians. This function returns the tangent of value passed as argument. The value passed in this function should be in radians.