SlideShare ist ein Scribd-Unternehmen logo
1 von 19
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.

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Recursion
RecursionRecursion
Recursion
 
Python recursion
Python recursionPython recursion
Python recursion
 
2D Array
2D Array 2D Array
2D Array
 
Array ppt
Array pptArray ppt
Array ppt
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Managing console input and output
Managing console input and outputManaging console input and output
Managing console input and output
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
NumPy
NumPyNumPy
NumPy
 
Introduction to numpy
Introduction to numpyIntroduction to numpy
Introduction to numpy
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Lists_tuples.pptx
Lists_tuples.pptxLists_tuples.pptx
Lists_tuples.pptx
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Array and string
Array and stringArray and string
Array and string
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Time and Space Complexity
Time and Space ComplexityTime and Space Complexity
Time and Space Complexity
 
Python - object oriented
Python - object orientedPython - object oriented
Python - object oriented
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 

Ähnlich wie INTRODUCTION TO FUNCTIONS IN PYTHON

Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdfsimenehanmut
 
The Input Statement in Core Python .pptx
The Input Statement in Core Python .pptxThe Input Statement in Core Python .pptx
The Input Statement in Core Python .pptxKavitha713564
 
Unit 2function in python.pptx
Unit 2function in python.pptxUnit 2function in python.pptx
Unit 2function in python.pptxvishnupriyapm4
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonCP-Union
 
Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfRamziFeghali
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionARVIND PANDE
 
Unit 2function in python.pptx
Unit 2function in python.pptxUnit 2function in python.pptx
Unit 2function in python.pptxvishnupriyapm4
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & ImportMohd Sajjad
 
Functions_19_20.pdf
Functions_19_20.pdfFunctions_19_20.pdf
Functions_19_20.pdfpaijitk
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptxkrushnaraj1
 
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUadAccount
 

Ähnlich wie INTRODUCTION TO FUNCTIONS IN PYTHON (20)

Functions.docx
Functions.docxFunctions.docx
Functions.docx
 
ch 2. Python module
ch 2. Python module ch 2. Python module
ch 2. Python module
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
 
Python Lecture 4
Python Lecture 4Python Lecture 4
Python Lecture 4
 
The Input Statement in Core Python .pptx
The Input Statement in Core Python .pptxThe Input Statement in Core Python .pptx
The Input Statement in Core Python .pptx
 
Unit 2function in python.pptx
Unit 2function in python.pptxUnit 2function in python.pptx
Unit 2function in python.pptx
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
 
python modules1522.pdf
python modules1522.pdfpython modules1522.pdf
python modules1522.pdf
 
Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdf
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
 
Unit 2function in python.pptx
Unit 2function in python.pptxUnit 2function in python.pptx
Unit 2function in python.pptx
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
 
Functions_19_20.pdf
Functions_19_20.pdfFunctions_19_20.pdf
Functions_19_20.pdf
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptx
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
Chapter04.pptx
Chapter04.pptxChapter04.pptx
Chapter04.pptx
 
Objects and Graphics
Objects and GraphicsObjects and Graphics
Objects and Graphics
 
Managing console input
Managing console inputManaging console input
Managing console input
 
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
 

Mehr von vikram mahendra

Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemvikram mahendra
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shopvikram mahendra
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMvikram mahendra
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Pythonvikram 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 PYTHONvikram mahendra
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONvikram mahendra
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONvikram mahendra
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1vikram mahendra
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2vikram 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 2vikram 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 PYTHONvikram mahendra
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]vikram mahendra
 

Mehr von vikram mahendra (20)

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

Kürzlich hochgeladen

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 

Kürzlich hochgeladen (20)

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 

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.