0% found this document useful (0 votes)
4 views6 pages

functions and modules (1)

The document explains the concepts of functions and modules in Python programming. Functions are reusable blocks of code defined with the 'def' keyword, while modules are files containing Python code that can be imported for use in other programs. It highlights the importance of organizing code for better maintenance and reusability, mentioning built-in modules like math and datetime.

Uploaded by

sreeram.mr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

functions and modules (1)

The document explains the concepts of functions and modules in Python programming. Functions are reusable blocks of code defined with the 'def' keyword, while modules are files containing Python code that can be imported for use in other programs. It highlights the importance of organizing code for better maintenance and reusability, mentioning built-in modules like math and datetime.

Uploaded by

sreeram.mr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

python programming

T H E P E R F E C T W A Y T O C O D E Y O U R F U T U R E

functions and
modules
Functions
In Python, a function is a block of code that performs a
specific task and can be reused throughout your program.
Functions in Python are defined using the def keyword,
followed by the function name, and then a set of
parentheses containing any parameters the function
requires. Here is an example of a simple function that takes
two arguments and returns their sum:
In this example, add_numbers() is the function name, and a
and b are the parameters. The function takes in two
numbers, adds them together, and returns the sum.
modules
A module in Python is a file containing Python code that can
be imported and used in other Python programs. Modules
are used to organize code into logical groups, making it
easier to maintain and reuse. Python comes with a large
number of built-in modules that provide a wide range of
functionality, such as math for mathematical operations,
datetime for working with dates and times, and random for
generating random numbers.
You can also create your own modules in Python by simply
creating a file with a .py extension and adding your code. To
use a module in your program, you can import it using the
import statement. For example, to use the math module, you
would use the following statement:

You might also like