About 132,000 results
Open links in new tab
  1. Python def Keyword - GeeksforGeeks

    Dec 27, 2024 · In Python, the def keyword is used to define functions and it can also be used to define methods inside a class. A method is a function that is associated with an object and is called using the instance of the class. When using def inside a class, we can define methods that can access and modify the attributes of the class and its instances.

  2. How to Call a Function in PythonDef Syntax Example

    Jul 20, 2022 · To define a function in Python, you type the def keyword first, then the function name and parentheses. To tell Python the function is a block of code, you specify a colon in front of the function name. What follows is what you want the function to do. The basic syntax of a function looks like this: An example of a function looks like this:

  3. Python def Keyword - W3Schools

    The def keyword is used to create, (or define) a function. Read more about functions in our Python Functions Tutorial. Python Keywords. Track your progress - it's free! Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.

  4. How To Define a Function in Python - LearnPython.com

    Apr 15, 2021 · We start with the def keyword to inform Python that a new function is being defined. Then, we give our function a meaningful name. Next, in parentheses, we list the arguments or parameters that the function needs to perform a task. You can include as many parameters as you want.

  5. How to Define a Function in Python? - Python Guides

    Feb 10, 2025 · To define a function in Python, you use the def keyword followed by the function name and parentheses. Inside the parentheses, you can specify parameters that the function can accept. After the parentheses, add a colon and start a new indented block for the function body. Here’s the general syntax for defining a function:

  6. Python Define Function: Step-by-Step Instructions

    A function is a block of reusable code that performs a specific task. Instead of repeating code, you define it once in a function and call it whenever needed. This helps in writing cleaner and more maintainable programs. Basic Syntax: How to Define a Function in Python. The basic syntax for defining a function is: def function_name(parameters ...

  7. Python User Defined Functions - GeeksforGeeks

    Feb 26, 2025 · These functions accept parameters (arguments) to process and return results dynamically. Parameters allow for flexibility, enabling the function to handle different inputs each time it is called. Explanation: fun (name) prints a greeting with the provided name. When called with “shakshi”, it outputs “Hello, shakshi”. 2.

  8. def | Python Keywords – Real Python

    In Python, the def keyword defines a function, which is a reusable block of code that may accept data input, perform a specific computation or task, and return a result or produce a side effect. Functions allow you to encapsulate a piece of logic and execute it whenever you need to by calling the function’s name with a pair of parentheses.

  9. Python Functions - Python Guides

    In Python, you define a function using the def keyword, followed by the function name and parameters in parentheses: def function_name(parameters): """Docstring: explains what the function does""" # Function body # Code to execute return result # Optional return statement ... They use the @decorator_name syntax. def my_decorator(func): def ...

  10. Mastering Python's def Function: A Comprehensive Guide

    Jan 24, 2025 · In Python, functions are defined using the def keyword. They can take zero or more inputs (parameters), perform operations on those inputs, and return a result. For example, you can create a function to calculate the square of a number, or to print a welcome message. A basic def function in Python has the following structure:

  11. Some results have been removed
Refresh