🐍
Python For Starters
  • Overview
  • Python for starters
  • Content
  • Foreword
  • Introduction To Python
    • Python Installation
    • Variables
    • Python Data Types
    • Python Data Structures
    • Python numbers
    • Python strings
    • Python Boolean
    • Python constants
    • Python Comments
    • Type Conversion
    • Control flow in python
  • Python Functions
    • Function Definition
    • Function Parameter
    • Recursive Functions
    • Using Global Variables in Functions
    • Lambda Functions
  • What are Data Structures
    • Python Lists
    • Python Tuples
    • Python Dictionaries
    • Python Sets
    • Iterable in python
    • Python Map, Filter & Reduce Functions
  • Error handling in Python
  • Loop ... Else Clause, Partial Functions & Type Hints
    • Partial Functions
    • Type Hints
  • Python Modules
  • Python Libraries & Packages
    • Python Packages
  • Directory & IO
    • Python IO Module
  • Pyenv
  • Virtual Environments
    • Pipenv
    • Virtualenv
  • Object Oriented Programming in Python
    • Class
    • Class Methods
    • Python Class Inheritance
    • Python Class Polymorphism
    • Python special methods
  • Appendix
  • Contributing
Powered by GitBook
On this page

Python Functions

What is a python function?

In Python, a function is a block of code that performs a specific task. Functions help you organize and reuse your code, making it more efficient and easier to understand.

Functions can also return multiple values, or no value at all. You can call a function multiple times in your code, and each time it will execute the code inside the function with the given input values.

Here are some important things to note about Python functions:

  • Functions are defined using the def keyword, followed by the name of the function and a set of parentheses that may include parameters.

  • The block of code that makes up the function is indented underneath the definition line.

  • Functions may take arguments (also called parameters) that are specified in the parentheses of the function definition. These arguments are used to pass information into the function when it is called.

  • Functions may return a value using the return keyword. If a function does not have a return statement, it returns None.

  • Functions can be called by using their name followed by a set of parentheses that may include arguments.

  • Functions can be defined inside other functions, in which case they are called inner functions. Inner functions can access the variables of the outer function in which they are defined.

  • Functions can be passed as arguments to other functions.

  • Python has many built-in functions, and you can also define your own custom functions.

PreviousControl flow in pythonNextFunction Definition

Last updated 1 year ago