GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Python Functions - GeeksforGeeks Python FunctionsLast Updated : 19 Sep, 2026 Python functions are reusable blocks of code used to perform a specific task. They help organize programs into smaller sections and execute the same logic whenever needed by calling the function. ![]() Defining a FunctionA function can be defined using def keyword. Below is the syntax to define a function: ![]() Here, we define a function using def that prints a welcome message when called.
Calling a FunctionAfter creating a function, call it by using the name of the functions followed by parenthesis containing parameters of that particular function.
Output Welcome to GFG We can also assign a Function to a variable, and call that function using that variable. Function ArgumentsArguments are values passed to a function when it is called. They allow functions to receive input data and perform operations using those values. Syntax
Example: In this example, function checks whether the number passed as an argument is even or odd.
Output Even Odd Types of Function ArgumentsPython supports different types of arguments that can be passed during a function call. 1. Default argument: Default argument use a predefined value when no value is passed during the function call.
Output x: 10 y: 50 Explanation:
2. Keyword Arguments: pass values using parameter names, so argument order does not matter.
Output Geeks Practice Geeks Practice Explanation: fname and lname are passed using parameter names and arguments can be provided in any order. 3. Positional Arguments: values are assigned to parameters based on their order in the function call.
Output Case-1: Hi, I am Olivia My age is 27 Case-2: Hi, I am 27 My age is Olivia Explanation:
4. Arbitrary Arguments: allow functions to accept multiple values. This is done using two special symbols:
Output Non-Keyword Arguments (*args): Hey Welcome Keyword Arguments (**kwargs): first == Geeks mid == for last == Geeks Explanation:
Function within FunctionsA function defined inside another function is called an inner function (or nested function). It is used to organize related logic and access variables from the outer function.
Output I love GeeksforGeeks Return StatementReturn is used to end a function and send a value back to the caller. It can return any data type, multiple values (packed into a tuple), or None if no value is given. Syntax
Parameters: expression is the value returned by the function. If no value is returned, it returns None by default.
Output 4 16 Explanation:
Pass by Reference and Pass by ValueVariables refer to objects. Function behavior depends on whether the object is mutable or immutable.
Output [20, 11, 12, 13] 10 Explanation:
Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |